1. Go to this page and download the library: Download keradus/traits 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/ */
keradus / traits example snippets
class Foo
{
public $baz;
}
$foo = new Foo();
$foo->vaz = 123; // PHP claims that code is OK, even if you misspelled variable name!
class Bar
{
use InaccessiblePropertiesProtectorTrait;
public $baz;
}
$bar = new Bar();
$bar->vaz = 123; // now PHP throws \LogicException
class Foo
{
use InnerClassCacheTrait;
public function square($x)
{
if (!isset($this->cache[$x])) {
$this->cache[$x] = $x * $x;
}
return $this->cache[$x];
}
}
class Foo
{
use InstanceCreationDisallowerTrait;
public static function createInstance()
{
return new static();
}
}
$foo = new Foo(); // PHP throws fatal error
$foo = Foo::createInstance(); // PHP throws \LogicException
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.