#46870 [Opn->Csd]: Fatal error on class abstraction with constants

From: Date: Wed, 17 Dec 2008 11:16:10 +0000
Subject: #46870 [Opn->Csd]: Fatal error on class abstraction with constants
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-132112@lists.php.net to get a copy of this message
 ID:               46870
 Updated by:       bjori@php.net
 Reported By:      alvin at livejournal dot dk
-Status:           Open
+Status:           Closed
 Bug Type:         Scripting Engine problem
 Operating System: Linux
 PHP Version:      5.2.8
 New Comment:

As of PHP5.3 you can use static:: (see http://php.net/lsb)


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

[2008-12-15 23:26:32] 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-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 (#132112) next »