php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #37052 Parent class constants are not overriden by sub classes in static methods
Submitted: 2006-04-12 11:28 UTC Modified: 2006-04-12 19:29 UTC
From: rael at grad dot icmc dot usp dot br Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.* OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: rael at grad dot icmc dot usp dot br
New email:
PHP Version: OS:

 

 [2006-04-12 11:28 UTC] rael at grad dot icmc dot usp dot br
Description:
------------
Parent class constants are not overriden by sub classes in static methods. Do this override is a common behave, like in Java language. This is a very important feature to construct good class hierarchies.

Reproduce code:
---------------
<?php


	class Father{

		const NAME = "John";

		public static function foo(){
			echo self::NAME;
		}

	}

	class Son extends Father{

		const NAME = "John Junior";

	}

	Son::foo();


?>

Expected result:
----------------
Output of "John Junior"

Actual result:
--------------
Output of "John"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-12 11:54 UTC] mike@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Late static binding is in consideration.

 [2006-04-12 15:09 UTC] rael at grad dot icmc dot usp dot br
Changed to Feature/Change Request.
 [2006-04-12 19:29 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This his nothing to do with overwriting consts. What you want is late static binding and for that we already have a patch and decided to do it if we are all happy with it (e.g. if the overall slowdown is not to big).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 16 11:01:31 2024 UTC