PHP code example of grottopress / setter
1. Go to this page and download the library: Download grottopress/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/ */
grottopress / setter example snippets
declare (strict_types = 1);
namespace Vendor;
use GrottoPress\Setter\SetterTrait;
class MyClass {
/**
* Import trait
*/
use SetterTrait;
private $changeMe;
private $leaveMeAlone;
/**
* Define your private setter method
* Method name should be of the format "set{$attrName}"
*/
private function setChangeMe($newValue)
{
$this->changeMe = $newValue;
}
// ...
}
// Instantiate
$object = new Vendor\MyClass();
// Try to set attributes
$object->changeMe = 'New Me!'; // => Works!
$object->leaveMeAlone = 'xyz'; // => Error: 'setLeaveMeAlone()' not defined