php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27265 Reflection API :: Reflection_Property fails when a const is passed
Submitted: 2004-02-15 15:00 UTC Modified: 2004-06-09 22:18 UTC
From: jw at jwscripts dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5CVS-2004-02-15 OS: *
Private report: No CVE-ID: None
 [2004-02-15 15:00 UTC] jw at jwscripts dot com
Description:
------------
When passing a constant to the constructor of the Reflection_Property class, an exception is thrown.

You can work around this, e.g., by creating an instance of the Reflection_Object class instead, but this isn't very pretty.

The same problem occurres when a constant with one or more uppercased characters is defined, e.g.:

const $TEST = "foo";

 

Reproduce code:
---------------
<?

class Foo {
	const TEST = "foo";
	// Fails too: static $TEST = "foo";
	// Success  : static $test = "foo";
}

class Types extends Reflection_Property {
	public function __construct($object, $name) {
		parent::__construct($object, $name);
	}
}

$types = new Types("Foo", "TEST");

?>

Expected result:
----------------
No output

Actual result:
--------------
Fatal error: Uncaught exception 'reflection_exception' with message 'Property Foo::$TEST does not exist' in [...] Stack trace: #0 [...](13): Types->__construct() #1 {main} thrown in [...] on line [...]


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-16 15:04 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

We are missing a class \'Reflection_Const\'.
 [2004-02-16 16:55 UTC] jw at jwscripts dot com
> We are missing a class 'Reflection_Const'.

IMO, you are not missing a Reflection_Const class, but a method isConst() in the Reflection_Property class.
 [2004-06-09 11:13 UTC] D dot Kingma at jool dot nl
I Think the problem your are describing is more that of that the reflectionProperty class constructor doesn't work well with properties that are written in capitals, as your example with static illustrates. When you remove the static keyword the problem is reproducable (You cannot initiate the reflectionProperty when the name of the property is in capitals).
 
[Workaround]
You could use the getProperties method of the reflectionClass object which will return the reflectionProperty object for variables that are written in capitals.
 [2004-06-09 22:18 UTC] jw at jwscripts dot com
Another workaround consists of first trying to create an instance of the ReflectionProperty class and when this fails, creating an instance of the ReflectionObject class and search for a match in the arrays returned by its getConstants() or getStaticProperties() method (whichever is appropriate).

Anyways, thanks for looking into this again. Great job everybody!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 13:01:36 2024 UTC