- FEATURES
- Autoload
- Class Reflection
-
Magic Methods
- Exceptions
- Late Static Binding
- Type Hinting
- SPL
- PHPUNIT
- PHAR
- COMPOSER
- Carbon
- Guzzle
- Faker
- Math
- Requests
- DESIGN PATTERNS
- Singleton Pattern
- Observer Pattern
- Strategy Pattern
- Dependency Injection
- Middleware
- Registry
- SYMFONY
- Routes
- Annotations
- Flex
- Controllers
- Doctrine
- Templating
- VERSIONS
- Php7.4
- Php8.0
- SECURITY
- Filter Input
- Remote Code Injection
- Sql Injection
- Session Fixation
- File Uploads
- Cross Site Scripting
- Spoofed Forms
- CSRF
- Session Hijacking
- MODERN PHP
- Composer
- Autoloader
- Package
- Releases
- Generators
- Dependency Injection
- Middleware
- CUSTOM FRAMEWORK
- App
- Http Foundation
- Front Controller
- Routing
- Render Controller
- Resolver
- SoC
- FRAMEWORKS
- Slim
- Symfony V5
- Laravel V8
- Laminas V3
- Codeigniter V4
Get magic method
All magic methods must be declared public.
class A
{
public function __get($var)
{
return 2;
}
}
$a = new A();
echo $a->foo; // 2
You can keep track of variables which are not defined inside the class.
class myController
{
private $_modelBroker = array();
public function __get($var)
{
if (strstr($var, 'model')) {
$modelKey = substr($var, 5);
if (in_array($modelKey,
array_keys($this->_modelBroker))) { // registered
return $this->_modelBroker[$modelKey];
} else { // not registered
eval('$model = new Model_'.$modelKey.'();');
$this->_modelBroker[$modelKey] = $model;
return $model;
}
}
}
}
class Model_Number
{
public $id = 123;
}
$controller = new myController();
echo $controller->modelNumber->id; // 123
// _get is called, because modelNumber is undefined
Magical
The function names bellow are magical in PHP classes.
__construct(), __destruct(),
__call(), __callStatic(),
__get(), __set(),
__isset(), __unset(),
__sleep(),
__wakeup(),
__toString(),
__invoke(),
__set_state(),
__clone()
__debugInfo()
Last update: 8 days ago