php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67785 Derived classes
Submitted: 2014-08-05 17:16 UTC Modified: 2015-06-28 22:03 UTC
From: joelm@php.net Assigned: stas (profile)
Status: Closed Package: PHP Language Specification
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2014-08-05 17:16 UTC] joelm@php.net
Description:
------------
https://github.com/php/php-langspec/blob/master/spec/14-classes.md#classes

Derived classes get mentioned a fair amount throughout section 14 but there is no one place that really pins down a lot of the rules about how derived classes work. Here are some questions I don't think the spec really answers that it should answer: 

 - What happens when a base class and a derived class both define a public instance property named $x? Specifically how does storage work in such cases? 
 (It appears that only one $x is allocated, and it has the initial value of the most-derived declaration.)

 - What happens when a base class defines a private instance property named $x and then a derived class declares a public or protected or private instance property named $x? Specifically how does storage work in such cases? (It appears that two $x’s are allocated.)

 - What happens when a base class defined a static property named $x and then a derived class declares a static property named $x? How does storage work in such cases? 

 - If the method body for C::foo defines a function static variable, and then D derives from C and D does not override method foo, how does storage for the function static work? 

 - What if there is a private instance method named "bar" and a non-private instance method named "bar" within the same inheritance hierarchy, and then a call site somewhere in the class hierarchy calls instance method "bar". Which "bar" gets called? 



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-28 22:03 UTC] stas@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: stas
 [2015-06-28 22:03 UTC] stas@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

I think the "Inheritance" section now covers this.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC