issues with classnames, staic class members and constants as variables

From: Date: Thu, 24 Apr 2008 06:18:55 +0000
Subject: issues with classnames, staic class members and constants as variables
Groups: php.qa 
Request: Send a blank email to php-qa+get-64221@lists.php.net to get a copy of this message
hello, i have recently submitted a post to php-general which no one answered so i am tuning to the qa list. previously, in php-5.2.4 it was possible to use a variable to hold a class name and use this variable to access public static members (both attributes and functions) and constants. it was also possible to use a variable to hold static member names and use them either with the concrete class name or the class name held in a variable. i have prepared 3 phpt files and ran them against php-5.2.4 on a 32 bit gentoo system, and also on a php-5.2.6_rc3 system (also 32 bit gentoo). following are the tests and the results. i would greatly appreciate help in getting this resolved or an explanation as to why its not working in subsequent versions (after 5.2.4) if anyone knows :) --TEST-- static members can be invoked whereby the class name and membernames are stored in variables --FILE-- <?php class A { public static $c = 6; public static function d() { echo 7; } } $a = 'A'; $c = 'c'; $d = 'd'; echo $a::$$c; echo $a::$d(); ?> --EXPECT-- 67 --TEST-- static member names in a variable can be used with constant classnames --FILE-- <?php class A { public static $c = 6; public static function d() { echo 7; } } $c = 'c'; $d = 'd'; echo A::$$c; echo A::$d(); ?> --EXPECT-- 67 --TEST-- class names in a variable can be used to invoke static class members and class constants --FILE-- <?php class A { const B = 5; public static $c = 6; public static function d() { echo 7; } } $a = 'A'; echo $a::B; echo $a::$c; echo $a::d(); ?> --EXPECT-- 567 ===================================================================== CWD : /home/nathan/unpack/phpunpack/php5.2-200708051230 PHP : /usr/bin/php PHP_SAPI : cli PHP_VERSION : 5.2.4-pl2-gentoo ZEND_VERSION: 2.2.0 PHP_OS : Linux - Linux trident 2.6.22-gentoo-r5 #15 SMP PREEMPT Sat Nov 3 14:12:59 EDT 2007 i686 INI actual : /etc/php/cli-php5/php.ini More .INIs : Extra dirs : ===================================================================== Running selected tests. PASS static members can be invoked whereby the class name and membernames are stored in variables [tests/classes/staticsAsVars/classNameAndStaticMembersInVars.phpt] PASS static member names in a variable can be used with constant classnames [tests/classes/staticsAsVars/staticAndConstMemberNamesAsVars.phpt] PASS class names in a variable can be used to invoke static class members and class constants [tests/classes/staticsAsVars/varWithClassAccessStatic.phpt] ===================================================================== Number of tests : 3 3 Tests skipped : 0 ( 0.0%) -------- Tests warned : 0 ( 0.0%) ( 0.0%) Tests failed : 0 ( 0.0%) ( 0.0%) Tests passed : 3 (100.0%) (100.0%) --------------------------------------------------------------------- Time taken : 0 seconds ===================================================================== ===================================================================== PHP : /usr/bin/php PHP_SAPI : cli PHP_VERSION : 5.2.6RC3-pl0-gentoo ZEND_VERSION: 2.2.0 PHP_OS : Linux - Linux devel 2.6.17-gentoo-r8 #42 Sun Sep 16 11:26:18 CDT 2007 i686 INI actual : /etc/php/cli-php5/php.ini More .INIs : CWD : /home/nathan/unpack/php-5.2.6RC3 Extra dirs : ===================================================================== Running selected tests. FAIL static members can be invoked whereby the class name and membernames are stored in variables [/home/nathan/unpack/tests/classes/staticsAsVars/classNameAndStaticMembersInVars.phpt] PASS static member names in a variable can be used with constant classnames [/home/nathan/unpack/tests/classes/staticsAsVars/staticAndConstMemberNamesAsVars.phpt] FAIL class names in a variable can be used to invoke static class members and class constants [/home/nathan/unpack/tests/classes/staticsAsVars/varWithClassAccessStatic.phpt] ===================================================================== Number of tests : 3 3 Tests skipped : 0 ( 0.0%) -------- Tests warned : 0 ( 0.0%) ( 0.0%) Tests failed : 2 ( 66.7%) ( 66.7%) Tests passed : 1 ( 33.3%) ( 33.3%) --------------------------------------------------------------------- Time taken : 0 seconds ===================================================================== ===================================================================== FAILED TEST SUMMARY --------------------------------------------------------------------- static members can be invoked whereby the class name and membernames are stored in variables [/home/nathan/unpack/tests/classes/staticsAsVars/classNameAndStaticMembersInVars.phpt] class names in a variable can be used to invoke static class members and class constants [/home/nathan/unpack/tests/classes/staticsAsVars/varWithClassAccessStatic.phpt] thx, -nathan ps. sorry about my posting format; its my first time posting to this list. im glad to supply the tests however is appropriate.

« previous php.qa (#64221) next »