PHP code example of zero-to-prod / dynamic-setter
1. Go to this page and download the library: Download zero-to-prod/dynamic-setter 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/ */
zero-to-prod / dynamic-setter example snippets
use Zerotoprod\StreamContext\DynamicSetter;
class User
{
use DynamicSetter;
public $name;
public $email;
}
$user = User::new()
->set_name('John Doe')
->set_email('[email protected]');
echo $user->name; // Output: John Doe
echo $user->email; // Output: [email protected]
class Address
{
use DynamicSetter;
public $city;
public $postalCode;
}
class Customer
{
use DynamicSetter;
public $name;
public $address;
}
$customer = Customer::new()
->set_name('Jane Doe')
->set_address(
Address::new()
->set_city('New York')
->set_postalCode('10001')
);
echo $customer->name; // Output: Jane Doe
echo $customer->address->city; // Output: New York
echo $customer->address->postalCode; // Output: 10001