- 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
Private
You can't access private property from outside a class.
class Foo
{
public $foo = 1;
protected $bar = 2;
private $baz = 3;
}
$obj = new Foo();
echo $obj->baz; // Fatal error: Cannot access private property
Reflexion
Use reflection to get private property.
class Foo
{
public $foo = 1;
protected $bar = 2;
private $baz = 3;
}
$obj = new Foo();
$reflector = new ReflectionObject($obj);
$property = $reflector->getProperty('baz');
$property->setAccessible(true);
echo $property->getValue($obj); // 3
Get private properties.
class Foo
{
public $foo = 1;
protected $bar = 2;
private $baz = 3;
}
$foo = new Foo();
$reflector = new ReflectionObject($foo);
$properties = $reflector->getProperties(ReflectionProperty::IS_PRIVATE |
ReflectionProperty::IS_PROTECTED);
array_map(function(&$x) { $x->setAccessible(true); }, $properties);
var_dump($properties);
/*
array (size=2)
0 =>
object(ReflectionProperty)[3]
public 'name' => string 'bar' (length=3)
public 'class' => string 'Foo' (length=3)
1 =>
object(ReflectionProperty)[4]
public 'name' => string 'baz' (length=3)
public 'class' => string 'Foo' (length=3)
*/
Get parent properties.
class Ford
{
private $model;
protected $foo;
public $bar;
}
class Car extends Ford
{
private $year;
}
$class = new ReflectionClass('Car');
var_dump($class->getProperties()); // First chunk of output
var_dump($class->getParentClass()->getProperties()); // Second chunk
Last update: 8 days ago