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
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: 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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 12:01:31 2025 UTC