php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48354 child constructor not executed
Submitted: 2009-05-21 12:54 UTC Modified: 2009-05-21 13:40 UTC
From: php_net at foq dot nl Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.9 OS: debian etch
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: php_net at foq dot nl
New email:
PHP Version: OS:

 

 [2009-05-21 12:54 UTC] php_net at foq dot nl
Description:
------------
I am using a base class and a lot of classes which extend that base class. When i add class variables in the base class i can use those in the extending class. All goed well. But when i set variables from the base class constructor then the extended class does not get these new values. I tested, and the base class constructor is not executed.

Reproduce code:
---------------
class base {
    var $mysql_link = null;
    var $test = "hello";

    function base() {
      $this->test = "helloolleh";
      $this->mysql_link = mysql_connect("host", "user", "pass");
      if(!$this->mysql_link)
        exit("mysql connection failed.");
    }
}

class photo extends base {
      photo() {
        print "photo constructor is working!\n";
        print "But the base class not: '".$this->test."'\n";
        mysql_query("Select foo from bar", $this->mysql_link) or die(mysql_error());
      }
}

$p = new photo();

Expected result:
----------------
photo constructor is working!
helloolleh
Error in query

Actual result:
--------------
 // nothing
hello
mysql: not a valid resource identifier

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-21 12:57 UTC] php_net at foq dot nl
photo() {

has to be 

function photo() {


I wrote this code as example by hand without testing because my code library is very huge. So that is not the main problem. The PHP code executes without any syntax errors.
 [2009-05-21 13:40 UTC] jani@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 11:01:37 2024 UTC