php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46870 Fatal error on class abstraction with constants
Submitted: 2008-12-15 15:30 UTC Modified: 2008-12-17 11:16 UTC
From: alvin at livejournal dot dk Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.2.8 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alvin at livejournal dot dk
New email:
PHP Version: OS:

 

 [2008-12-15 15:30 UTC] alvin at livejournal dot dk
Description:
------------
If an abstract class attempts to access a class constant defined by its parent, a fatal error is issued.

Reproduce code:
---------------
<?php
abstract class A
{
	public function foo ()
	{
		echo $this->bar; //works
		echo self::BAR; //fatal error
	}
}

class B extends A
{
	public $bar = 'foovar';
	const BAR = 'fooconst';
}

$x = new B;
$x->foo();
?>

Expected result:
----------------
foovarfooconst

Actual result:
--------------
foovar
Fatal error: Undefined class constant 'BAR' in...


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-15 23:26 UTC] crrodriguez at opensuse dot org
looks like expected behavior...self::BAR is not defined, self::BAR refers to the same __class__ constant "BAR" not to the __instance__ in this case.
 [2008-12-17 11:16 UTC] bjori@php.net
As of PHP5.3 you can use static:: (see http://php.net/lsb)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Aug 04 17:00:03 2025 UTC