php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61397 referencing class during static access using variable doesn't work properly
Submitted: 2012-03-15 09:42 UTC Modified: 2013-12-22 11:56 UTC
From: willewendell at gmail dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.3.10 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: willewendell at gmail dot com
New email:
PHP Version: OS:

 

 [2012-03-15 09:42 UTC] willewendell at gmail dot com
Description:
------------
Documentation says: "As of PHP 5.3.0, it's possible to reference the class using a variable. The variable's value can not be a keyword (e.g. self, parent and static)."

It does not say that class variables cannot be used, but trying to do so will result in the completely nonsensical error for non-hebrew speakers.

referencing the variable that references the class name does work, but it is a useless line in my code, i don't like it.
	public function foo() {
		$tmp =& $this->bar;
		echo $tmp::$my_static;
	}

Test script:
---------------
<?php 
class Foo {
	public static $my_static = 'foo';
}

class Bar {
	protected $bar; 
	public function __construct() {
		$this->bar = 'Foo';
	}
	public function foo() {
		echo $this->bar::$my_static;
	}
}

$bar = new Bar();
$bar->foo();

Expected result:
----------------
foo

Actual result:
--------------
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting ',' or ';' in C:\ ... \test.php on line 12

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-06 08:19 UTC] mike@php.net
-Type: Bug +Type: Documentation Problem
 [2013-12-22 11:56 UTC] salathe@php.net
-Status: Open +Status: Wont fix
 [2013-12-22 11:56 UTC] salathe@php.net
$foo->bar is not "a variable".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 13:01:26 2025 UTC