PHP code example of rakshazi / get-set-trait

1. Go to this page and download the library: Download rakshazi/get-set-trait 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/ */

    

rakshazi / get-set-trait example snippets


class Dummy
{
    //Add ability to use dynamic getters and setters
    use \Rakshazi\GetSetTrait;
}

//Init dummy class
$dummy = new Dummy;
//Set new var 'message_for_world' with value
$dummy->setMessageForWorld('Hello');
//Will return "Hello\n"
echo $dummy->getMessageForWorld()."\n";
//Will return the same text
echo $dummy->getData('message_for_world')."\n";
//Set new message for our world!
$dummy->setData('message_for_world', 'Bye-bye!');
//Will return "Bye-bye!\n"
echo $dummy->getData('message_for_world')."\n";
//Will set new var 'new_message'
$dummy->setNewMessage('Use me now!');
//Will return true, value exists
$dummy->hasNewMessage();
//Will return false
$dummy->hasSomeOtherValue();
//Will show all object data
var_dump($dummy);


class Dummy
{
    //Add ability to use dynamic getters and setters
    use \Rakshazi\GetSetTrait;

    public function __construct()
    {
        $this->setDataProperty('data');
    }
}

//Init dummy class
$dummy = new Dummy;
//Set new var 'message_for_world' with value
$dummy->setMessageForWorld('Hello');
//Will return "Hello\n"
echo $dummy->getMessageForWorld()."\n";
//Will return the same text
echo $dummy->getData('message_for_world')."\n";
//Set new message for our world!
$dummy->setData('message_for_world', 'Bye-bye!');
//Will return "Bye-bye!\n"
echo $dummy->getData('message_for_world')."\n";
//Will set new var 'new_message'
$dummy->setNewMessage('Use me now!');
//Will return all properties in an array
$dummy->getAllData();
//Will show all object data
var_dump($dummy);