PHP code example of lavoiesl / php-abstract-structure
1. Go to this page and download the library: Download lavoiesl/php-abstract-structure 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/ */
lavoiesl / php-abstract-structure example snippets
use Lavoiesl\AbstractStructure\AbstractStructure;
class Generic extends AbstractStructure
{
protected $foo;
}
$generic = new Generic;
$generic->foo = 1; // initial value
$generic->foo = 2; // type not changing, still good
$generic->foo = 'foo'; // Exception, wrong type
$generic->bar = 'foo'; // Exception, undefined
use Lavoiesl\AbstractStructure\AbstractStructure;
class Article extends AbstractStructure
{
protected $id;
public function getPropertyType($property)
{
switch ($property) {
case 'id': return 'integer|null';
}
}
}
$generic = new Article;
$generic->id = 1;
$generic->id = null;
$generic->id = 'foo'; // Exception