note 129111 added to reflectionproperty.setaccessible

From: Date: Tue, 19 Dec 2023 10:11:30 +0000
Subject: note 129111 added to reflectionproperty.setaccessible
Groups: php.notes 
Request: Send a blank email to php-notes+get-221065@lists.php.net to get a copy of this message
<?php namespace App; class Person { private $age; function __construct($age = 20) { $this->age = $age; } } namespace AppClient; $reflectionObj = new \ReflectionClass('App\Person'); $instance = $reflectionObj->newInstance(18); // Error: Uncaught ReflectionException: Cannot access non-public member App\Person::$age $reflectionObj->getProperty('age')->setAccessible(true); var_dump($reflectionObj->getProperty('age')->getValue($instance)); // it is right $ageProperty = $reflectionObj->getProperty('age'); $ageProperty->setAccessible(true); var_dump($ageProperty->getValue($instance)); ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.134 (proxied: 108.181.26.106) ---- Manual Page -- https://php.net/manual/en/reflectionproperty.setaccessible.php Edit -- https://main.php.net/note/edit/129111 Del: integrated -- https://main.php.net/note/delete/129111/integrated Del: useless -- https://main.php.net/note/delete/129111/useless Del: bad code -- https://main.php.net/note/delete/129111/bad+code Del: spam -- https://main.php.net/note/delete/129111/spam Del: non-english -- https://main.php.net/note/delete/129111/non-english Del: in docs -- https://main.php.net/note/delete/129111/in+docs Del: other reasons-- https://main.php.net/note/delete/129111 Reject -- https://main.php.net/note/reject/129111 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221065) next »