• Startpagina
  • Hulpprogramma's
  • Contact
David van der Tuijn
David van der Tuijn
Certified Laravel Developer
13 january 2023
How can I access private properties in PHP?
function getPrivateProperty($obj, string $property) {
    $r = new ReflectionObject($obj);
    $p = $r->getProperty($property);
    $p->setAccessible(true);

    return $p->getValue($obj);
}

Meer informatie:

  • PHP: ReflectionClass::getProperty - Manual
  • PHP: ReflectionObject - Manual
  • PHP: ReflectionProperty::setAccessible - Manual

Categorieën:

PHP

Tags:

ReflectionClass ReflectionObject ReflectionProperty
Uitgelichte artikelen
7 april 2022
Hide Email
7 march 2022
Geo Distance
6 december 2021
Certified Laravel Developer
4 june 2016
International Bank Account Number (IBAN) Validator
1 december 2012
Convert English or French notation to decimal