PHP code example of alaa-almaliki / property-setter-config
1. Go to this page and download the library: Download alaa-almaliki/property-setter-config library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alaa-almaliki / property-setter-config example snippets
class MyClass
{
private $firstName;
private $lastName;
private $email;
private $friends = [];
public function __construct(array $config = [])
{
PropertySetterConfig::setObjectProperties($this, $config);
}
public function setFirstName($value)
{
$this->firstName = $value;
}
public function getFirstName()
{
return $this->firstName;
}
public function setLastName($value)
{
$this->lastName = $value;
return $this;
}
public function getLastName()
{
return $this->lastName;
}
public function setEmail($value)
{
$this->email = $value;
return $this;
}
public function getEmail()
{
return $this->email;
}
public function setFriends(array $value)
{
$this->friends = $value;
return $this;
}
public function getFriends()
{
return $this->friends;
}
}
$obj = new MyClass([
'first_name' => 'alaa',
'last_name' => 'almaliki',
'email' => '[email protected]',
'friends' => [
'Adam',
'Melissa',
'laith',
'Ahmed'
]
]);