php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #43881 Example #1 for class constants shows error
Submitted: 2008-01-17 18:04 UTC Modified: 2008-01-17 19:06 UTC
From: paramount_98 at hotmail dot com Assigned: colder (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.2.5 OS: RHEL 5
Private report: No CVE-ID: None
 [2008-01-17 18:04 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-17 18:05 UTC] 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:15 UTC] 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:18 UTC] bjori@php.net
Examples requiring specific PHP versions should be commented as such.

Etienne: Please fix all the examples (if more) referring to this feature (and LSB).
 [2008-01-17 19:06 UTC] colder@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:10 UTC] phpdocbot@php.net
Automatic comment on behalf of colder
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=8d41f6f31506544d4e1befdaaed54dac91f0e288
Log: Fix #43881 (Specify the version in the example)
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 12:00:02 2026 UTC