Reputation: 495
I am trying to create a php class that will take in data from multiple child classes and display the value at the end
class ManifestBuilder
{
static $manifest;
function __construct( )
{
$this->get_manifest( );
}
function get_manifest( )
{
include 'manifest.php';
include 'sub1/manifest.php';
include 'sub2/manifest.php';
var_dump ( ManifestBuilder::$manifest );
}
function add_manifest( $var )
{
ManifestBuilder::$manifest .= $var;
}
}
new ManifestBuilder( );
Each child looks like this
class Manifest extends ManifestBuilder
{
function __construct( )
{
$this->manifest( );
}
function manifest( )
{
parent::add_manifest( 'manifest1' );
}
}
new Manifest( );
The problem is that I want to name the class the same on each child so I can easily move them around, but I am getting an error that class names cannot be the same (expected).
How can I solve this? I want to have multiple child classes be able to add to a variable in the parent class.
Thanks.
Upvotes: 0
Views: 897
Reputation: 175098
You can't. It's as simple as that.
And it makes sense too. If you need further functionality on the same class, simply refactor it. If you need a child class, extend it.
Upvotes: 2