#46870 [Com]: Fatal error on class abstraction with constants

From: Date: Mon, 15 Dec 2008 23:26:33 +0000
Subject: #46870 [Com]: Fatal error on class abstraction with constants
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-132005@lists.php.net to get a copy of this message
 ID:               46870
 Comment by:       crrodriguez at opensuse dot org
 Reported By:      alvin at livejournal dot dk
 Status:           Open
 Bug Type:         Scripting Engine problem
 Operating System: Linux
 PHP Version:      5.2.8
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2008-12-15 15:30:43] 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...



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=46870&edit=1



Thread (3 messages)

« previous php.bugs (#132005) next »