[nycphp-talk] Intellectual Monday

Cliff Hirsch cliff at
Tue Jan 23 09:22:51 EST 2007

That's pretty cool. Maddening to read, but very powerful.

-----Original Message-----
From: talk-bounces at [mailto:talk-bounces at]
On Behalf Of Rob Marscher
Sent: Monday, January 22, 2007 3:38 PM
To: NYPHP Talk
Subject: Re: [nycphp-talk] Intellectual Monday

A lot of the methods in the Zend Framework classes use object chaining.

It requires PHP5.  In terms of the prototype concept... javascript 
doesn't have a traditional object implementation -- you can't say "class

A extends class B" -- and the lines are pretty blurred between what a 
function is and what an object is, so that why you kind of have to hack 
it via the prototype object to achieve some sense of object-oriented 

Here's the idea of object chaining in php:
class SomeClass
  function doSomething()
    echo "Something\n";
    return $this;
  function getOther()
    if (!isset($this->other))
       $this->other = new OtherClass();
     return $this->other;
class OtherClass
  function doSomethingElse()
    echo "Something Else\n";
    return $this;
$foo = new SomeClass();


csnyder wrote:
> On 1/22/07, Cliff Hirsch <cliff at> wrote:
>> I wonder how these techniques work in the PHP world. Does anyone use
>> chaining effectively? Is there a PHP equivalent to the prototype 
>> concept?
> Javascript is an beautiful, powerful language. I never thought I would
> say that, and I think Netscape could have done so much more "back in
> the day" to produce good documentation and examples. That's what
> Prototype, MochiKit, jQuery, et al are finally doing.
> Anyway, PHP's object support doesn't really compare. Classes are not
> the same as prototypes. And not everything in PHP is an object,
> therefore chaining is a kludge at best.
>> From the point of view of readability and maintainability, I hope
> developers *aren't* trying to replicate Javascript patterns in PHP...
New York PHP Community Talk Mailing List

NYPHPCon 2006 Presentations Online

Show Your Participation in New York PHP

More information about the talk mailing list