By the way, it can be done like this...
PHP Code:
<?php
error_reporting(E_ALL);
class mainClass {
var $mainVar = '1234'; // explicitly set the value
function mainClass() {
$this->mainVar = 'abcd'; // now change the value
return true;
}
function returnMainVar() {
return $this->mainVar; // which value does it return, 1234 or abcd?
}
}
class subClass extends mainClass {
function subClass( $main ) {
$this->mainVar = $main->mainVar;
return true;
}
function showVar() {
return $this->mainVar;
}
}
$main = &new mainClass();
$sub = &new subClass( $main );
echo 'Printing variable display from main class: ' . $main->returnMainVar();
echo '<br>';
echo 'Printing variable display from sub class: ' . $sub->showVar();
?>
This is straight from the article. I'm passing $main to subClass and accessing the instance from there. This feels really inefficient... I'm eager to hear anyone's thoughts though.
Bookmarks