Created
February 14, 2021 15:40
-
-
Save ivastly/152fa00f24916c137137275b24c39218 to your computer and use it in GitHub Desktop.
Usage of php-reflection library - reading private property of an object in PHP.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
require_once __DIR__ . '/../vendor/autoload.php'; | |
class ParentClass | |
{ | |
private $property = 'parent private property'; | |
} | |
class C extends ParentClass | |
{ | |
} | |
$object = new C(); | |
$reflection = new \Ivastly\PhpReflection\Reflection(); | |
$value = $reflection->getProperty($object, 'property'); | |
$visibility = $reflection->getVisibility($object, 'property'); | |
echo "$visibility \$property = '$value;'\n"; // private $property = 'parent private property'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment