I would like to know if there is anyway I can make a parent object with php, I have tried this:
new parent::__construct($var);
but it doesn't work and I get the following error in the php logs:
(..)PHP Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$'(..)
Just call the constructor of the parent class like:
$parentClassObject = new ParentClassName();
Use parent::__construct() to call the parent class constructor since it is not done automatically in PHP.
This might work:
$parentClass = get_parent_class();
$parentObject = new $parentClass();
see http://uk.php.net/get_parent_class
<?php
class Foo {
}
class Bar extends Foo {
protected $p;
public function __construct() {
$pc = get_parent_class();
$this->p = new $pc;
}
}
$bar = new Bar;
var_dump($bar);
(But somehow I fail to see why you would need something like that. But maybe that's just me.... ;-))