[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-doc-bugs
Subject:    [DOC-BUGS] Doc #63832 [Opn]: Doc don't fully cover constructor inheritance
From:       "jschoett at gmail dot com" <php-bugs () lists ! php ! net>
Date:       2012-12-27 9:17:25
Message-ID: E1To9af-0006xT-0W () sgrv2 ! php ! net
[Download RAW message or body]

Edit report at https://bugs.php.net/bug.php?id=63832&edit=1

 ID:                 63832
 User updated by:    jschoett at gmail dot com
 Reported by:        jschoett at gmail dot com
-Summary:            Doc don't fully cover constr. inheritance
+Summary:            Doc don't fully cover constructor inheritance
 Status:             Open
 Type:               Documentation Problem
 Package:            Documentation problem
 Operating System:   Doc problem
 PHP Version:        5.4.10
 Block user comment: N
 Private report:     N

 New Comment:

just title adapted.


Previous Comments:
------------------------------------------------------------------------
[2012-12-21 21:03:37] jschoett at gmail dot com

Description:
------------
---
From manual page: http://www.php.net/language.oop5.decon
---
I can not find a definite statement on this:
"The child class inherits the constructor of the base class, iff the child class 
does not explicitly define an own constructor."

The documentation do not cover this with:
"Note: Parent constructors are not called implicitly if the child class defines a 
constructor"

In addition, since this is an significant difference to e.g. Java, it should be 
documented

Test script:
---------------
Snippet to validate this statement (I know you already know the result):
<?php
class A {
    private $x = null;
    function __construct($x) {
        $this->x = $x;
    }
}
class B extends A { }
$b1 = new B(); // Warning: Missing argument 1 for A::__construct()
$b2 = new B(1);
var_dump($b1); // Notice: Undefined variable: x
var_dump($b2);
?>

Expected result:
----------------
Same as actual, but I wan't it to be documented :)

Actual result:
--------------
Warning: Missing argument 1 for A::__construct(), called in path\testoutput.php on 
line 28 and defined in path\testoutput.php on line 21

Notice: Undefined variable: x in path\testoutput.php on line 22
object(B)#1 (1) { ["x":"A":private]=> NULL } object(B)#2 (1) { ["x":"A":private]=> 
int(1) }


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



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

-- 
PHP Documentation Bugs Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic