#29986 [Com]: Class constants won't work with predefined constants when using ReflectionClass

From: Date: Fri, 24 Feb 2006 14:52:07 +0000
Subject: #29986 [Com]: Class constants won't work with predefined constants when using ReflectionClass
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-93631@lists.php.net to get a copy of this message
ID: 29986 Comment by: RQuadling at GMail dot com Reported By: mitchel at sahertian dot com Status: No Feedback Bug Type: Scripting Engine problem Operating System: Linux 2.6.8.1 x86 PHP Version: 5.0.1 New Comment: Windows XP SP2 running the latest PHP. PHP 5.1.3-dev (cli) (built: Feb 20 2006 00:29:25) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies with Zend Extension Manager v1.0.10, Copyright (c) 2003-2006, by Zend Technologies with Zend Optimizer v3.0.0-Beta2, Copyright (c) 1998-2006, by Zend Technologies Reproduce code: --------------- <?php class just_constants { // These don't work. const BOOLEAN_CONSTANT = True; const NULL_CONSTANT = Null; // These do work. const STRING_CONSTANT = 'This is a string'; const INTEGER_CONSTANT = 1000; const FLOAT_CONSTANT = 3.1415926535897932384626433832795; } Reflection::export(new ReflectionClass('just_constants')); ?> Expected result: ---------------- Class [ <user> class just_constants ] { @@ D:\Data\PHP\Includes\ERT\rcerr.php 2-10 - Constants [5] { Constant [ boolean BOOLEAN_CONSTANT ] { } Constant [ null NULL_CONSTANT ] { } Constant [ string STRING_CONSTANT ] { } Constant [ integer INTEGER_CONSTANT ] { } Constant [ double FLOAT_CONSTANT ] { } } - Static properties [0] { } - Static methods [0] { } - Properties [0] { } - Methods [0] { } } Actual result: -------------- Class [ <user> class just_constants ] { @@ D:\Data\PHP\Includes\ERT\rcerr.php 2-10 - Constants [5] { Constant [ unknown BOOLEAN_CONSTANT ] { } Constant [ unknown NULL_CONSTANT ] { } Constant [ string STRING_CONSTANT ] { } Constant [ integer INTEGER_CONSTANT ] { } Constant [ double FLOAT_CONSTANT ] { } } - Static properties [0] { } - Static methods [0] { } - Properties [0] { } - Methods [0] { } } In zend_API.c (/* $Id: zend_API.c,v 1.347 2006/02/22 12:02:44 dmitry Exp $ */) Lines 217 to 250 - zend_zval_type_name() has the capability to return the 'boolean' and 'null' values. Though 'string' is shown as 'native string' in the source code and that change was made V1.304 17/08/2005 but has not been compiled maybe? Is the zend engine slow to update as compared to the main PHP code? Are there other changes not being made here? I did a binary search on all of the dlls and exes and no mention of 'native string'. At around byte 0x2728B0 in php5ts.dll the text for the return values from the zend_zval_type_name function are stored. Previous Comments: ------------------------------------------------------------------------ [2004-10-20 01:00:05] php-bugs at lists dot php dot net No feedback was provided for this bug for over a week, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open". ------------------------------------------------------------------------ [2004-10-12 09:33:24] derick@php.net Please try using this CVS snapshot: http://snaps.php.net/php5-latest.tar.gz For Windows: http://snaps.php.net/win32/php5-win32-latest.zip ------------------------------------------------------------------------ [2004-10-12 09:27:52] php at bobsilva dot com This is fixed in 5.1 CVS ------------------------------------------------------------------------ [2004-09-08 16:08:43] ante dot dfg at moj dot net Interestingly enough this example(btw there's an error at end of DEFINE - define("FOOBAR",0x0008): <- this should be ;) when copy paste and run dies with Fatal error: Trying to clone an uncloneable object of class ReflectionClass in c:\serverroot\test.php on line 11 but If I put a reference in $o=new ReflectionClass("MyClass"); making it $o=&new ReflectionClass("MyClass"); then I actualy get the message ("actual result") that Michael stated.... I'm using php 5.0.1 (release version) on XP Pro under Apache 1.3.31.... Hope this helps somehow... ------------------------------------------------------------------------ [2004-09-05 15:40:22] mitchel at sahertian dot com Description: ------------ I have a variable classname i have to get a constant/static property from. ${$classname}::stuff doesn't work, so i have to use the reflection api. This works for strings and numbers, but when i try to use getConstant() upon a constant that is defined as another constant, it returns UNKNOWN:0. This happens for user defined constants as well as things like `true'. Reproduce code: --------------- <?php define("FOOBAR",0x0008): class Myclass { const foo = true; const bar = FOOBAR; const works = "yes it does"; } $o=new ReflectionClass("MyClass"); var_dump($o->getConstant("foo")); var_dump($o->getConstant("bar")); var_dump($o->getConstant("works")); ?> Expected result: ---------------- bool(true) int(8) string(11) "yes it does" Actual result: -------------- UNKNOWN:0 UNKNOWN:0 string(11) "yes it does" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29986&edit=1

« previous php.bugs (#93631) next »