By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,607 Members | 1,944 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,607 IT Pros & Developers. It's quick & easy.

OOP Marshalling(?) in PHP

P: n/a
I want to marshall the features of two different classes into one
object. Is there a certain way to do this in PHP?

Effectively, I'm trying to do something like:

class clsBread extends clsFlour, clsEggs

Jul 27 '07 #1
Share this Question
Share on Google+
10 Replies


P: n/a
On 28 Jul., 01:33, Sanders Kaufman <bu...@kaufman.netwrote:
I want to marshall the features of two different classes into one
object. Is there a certain way to do this in PHP?

Effectively, I'm trying to do something like:

class clsBread extends clsFlour, clsEggs

No, mutiple Inheritage is not supported.

Jul 28 '07 #2

P: n/a
..oO(Sanders Kaufman)
>I want to marshall the features of two different classes into one
object.
Marshalling is something different, but anyway.
>Is there a certain way to do this in PHP?

Effectively, I'm trying to do something like:

class clsBread extends clsFlour, clsEggs
Multiple inheritance is not supported in PHP. But there are some
concepts to accomplish a similar effect:

* interfaces (PHP 5)

<http://www.php.net/manual/en/language.oop5.interfaces.php>

* delegation/aggregation

<http://en.wikipedia.org/wiki/Delegation_(programming)>

Micha
Jul 28 '07 #3

P: n/a
Sanders Kaufman wrote:
class clsBread extends clsFlour, clsEggs
class clsBread extends clsFlour
{
public function __construct ()
{
aggregate($this, 'clsEggs');
}
}

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 37 days, 11:54.]

Cryptography Challenge
http://tobyinkster.co.uk/blog/2007/0...pto-challenge/
Jul 28 '07 #4

P: n/a
Toby A Inkster wrote:
Sanders Kaufman wrote:
>class clsBread extends clsFlour, clsEggs

class clsBread extends clsFlour
{
public function __construct ()
{
aggregate($this, 'clsEggs');
}
}
It's aggregation, not inheritance.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 28 '07 #5

P: n/a
Toby A Inkster wrote:
Sanders Kaufman wrote:
>class clsBread extends clsFlour, clsEggs

class clsBread extends clsFlour
{
public function __construct ()
{
aggregate($this, 'clsEggs');
}
}
Dagnabbit. That's a PHP5 thing, ain't it?
Jul 28 '07 #6

P: n/a
>class clsBread extends clsFlour
>{
public function __construct ()
{
aggregate($this, 'clsEggs');
}
}

Dagnabbit. That's a PHP5 thing, ain't it?
No it was introduced into php 4.2

http://php.net/aggregate
Jul 28 '07 #7

P: n/a
peter wrote:
>>class clsBread extends clsFlour
{
public function __construct ()
{
aggregate($this, 'clsEggs');
}
}
Dagnabbit. That's a PHP5 thing, ain't it?

No it was introduced into php 4.2

http://php.net/aggregate
Holy Mackerell! I had no idea that was there. What an interestingly
weird set of functions.

Unfortunately my hosting provider didn't build PHP4 with the classkit I
guess - because it doesn't seem to be enabled.

Also, PHP is REAL good about remaining backward compatible with its own
previous versions - but this feature didn't seem to make the cut for PHP5.

While it's an interesting concept - dynamic aggregation - it seems like
a dead end in PHP.

Other than MySQL support, my project really isn't much good if the end
user has to have these kinds of non-standard features enabled - even if
they are pretty cool.
Jul 29 '07 #8

P: n/a
Jerry Stuckle wrote:
It's aggregation, not inheritance.
Despite the name of the function, aggregate() actually does something a
lot closer to multiple-inheritance than what is normally considered
aggregation. The properties and methods of the "aggregated" class are
taken on by the given object.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 38 days, 12:48.]

Cryptography Challenge
http://tobyinkster.co.uk/blog/2007/0...pto-challenge/
Jul 29 '07 #9

P: n/a
Sanders Kaufman wrote:
Also, PHP is REAL good about remaining backward compatible with its own
previous versions - but this feature didn't seem to make the cut for PHP5.
In PHP5, you don't need hacks like aggregate(). You can implement
multi-inheritance just using the standard PHP5 OO features: by overloading
__get(), __set(), __unset(), __isset() and __call().

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 38 days, 12:50.]

Cryptography Challenge
http://tobyinkster.co.uk/blog/2007/0...pto-challenge/
Jul 29 '07 #10

P: n/a
Toby A Inkster wrote:
Jerry Stuckle wrote:
>It's aggregation, not inheritance.

Despite the name of the function, aggregate() actually does something a
lot closer to multiple-inheritance than what is normally considered
aggregation. The properties and methods of the "aggregated" class are
taken on by the given object.
The way I solved this, I think, is to have one class that extends a base
class, and then another that extends the extended base class.

I *think* it'll work - but I cant' be sure until I try it or one of
y'all says it won't.
Jul 29 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.