|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 13:00:01 2025 UTC |
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.