1. Go to this page and download the library: Download aesonus/php-magic 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/ */
aesonus / php-magic example snippets
class MyClass {
use HasMagicProperties;
// or
use HasInheritedMagicProperties;
}
use \stdClass;
/**
* Yup, the question mark can be used to indicate null
* @property ?string $testStringOrNullProperty Optional description
* The | can validate using 'or'
* @property float|string $testFloatOrStringProperty
* @property-read int $testIntReadProperty
* @property-read callable|object $testCallableOrObjectReadProperty
* @property-write stdClass|null $testStdClassOrNullWriteProperty
* @property-write mixed $testMixedWriteProperty
*/
class MyClass {
use HasMagicProperties;
protected $testStringOrNullProperty;
protected $testFloatOrStringProperty;
protected $testIntReadProperty;
protected $testCallableOrObjectReadProperty;
protected $testStdClassOrNullWriteProperty;
protected $testMixedWriteProperty;
...
}
/**
* ...
*/
class MyClass {
use HasMagicProperties;
/**
* Only readable properties will be read (@property or @property-read)
*/
public function __get($name)
{
return $this->magicGet($name);
}
/**
* Only readable properties will be read (@property or @property-read)
*/
public function __isset($name)
{
return $this->magicIsset($name);
}
/**
* Only writable properties will be set (@property or @property-write)
*/
public function __set($name, $value)
{
$this->magicSet($name, $value);
}
/**
* Only writeable properties will be set (@property or @property-write)
*/
public function __unset($name)
{
$this->magicUnset($name);
}
...
}
/**
* ...
*/
class MyClass {
use HasMagicProperties;
use ImplementsMagicMethods;
...
}
/**
* ...
*/
class MyClass {
public function __get($name)
{
// Do something
return $this->magicGet($name);
}
public function __set($name, $value)
{
$this->magicSet($name, $value);
//Manipulate the set value after the validation, if wanted
}
...
}
use My\Namespace\Foo;
use My\Other\Namspace\Bar;
/**
*
* @property $myClass Foo|Bar
*/
class MyClass {
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.