#43881 [Bgs->Asn]: Example #1 for class constants shows error

From: Date: Thu, 17 Jan 2008 18:18:17 +0000
Subject: #43881 [Bgs->Asn]: Example #1 for class constants shows error
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-450@lists.php.net to get a copy of this message
ID: 43881 Updated by: bjori@php.net Reported By: paramount_98 at hotmail dot com -Status: Bogus +Status: Assigned Bug Type: Documentation problem Operating System: RHEL 5 PHP Version: 5.2.5 -Assigned To: +Assigned To: colder New Comment: Examples requiring specific PHP versions should be commented as such. Etienne: Please fix all the examples (if more) referring to this feature (and LSB). Previous Comments: ------------------------------------------------------------------------ [2008-01-17 18:15:22] felipe@php.net Above on page: "As of PHP 5.3.0, it's possible to reference the class using a variable. Keywords like self, parent or static are not allowed in dynamic class references." ------------------------------------------------------------------------ [2008-01-17 18:05:04] paramount_98 at hotmail dot com This is referring to the documentation at http://www.php.net/manual/en/language.oop5.constants.php ------------------------------------------------------------------------ [2008-01-17 18:04:21] paramount_98 at hotmail dot com Description: ------------ Run example #1 on PHP 5.2.5 produces parse error. Reproduce code: --------------- <?php class MyClass { const constant = 'constant value'; function showConstant() { echo self::constant . "\n"; } } echo MyClass::constant . "\n"; $classname = "MyClass"; echo $classname::constant . "\n"; $class = new MyClass(); $class->showConstant(); echo $class::constant."\n"; ?> Expected result: ---------------- outputs 'constant value' Actual result: -------------- Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting ',' or ';' in /www/mydomain.com/httpdocs/class-constant-test.php on line 14 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43881&edit=1

« previous php.doc.bugs (#450) next »