Inheretance VS passing classes

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

iconofsin
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Jun 05, 2014 2:30 pm

Inheretance VS passing classes

Postby iconofsin » Thu Jun 05, 2014 2:37 pm

Is there any functional difference between the two following pieces of code other than the fact that with extended/inherited classes the properties of the parent class would be lost if they matched a property of the child class.

------------------

class foo
{
public $A;
}

class bar extends foo
{
}

$C = new bar();
$C->A;

-------------------------

class foo
{
public $A;
}

class bar
{
public $B;
}

$C = new bar();
$C->B = new foo();
$C->B->A;

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 3 guests