|
Posted by Jeff on 03/20/07 17:34
On Mar 19, 12:45 pm, "ZeldorBlat" <zeldorb...@gmail.com> wrote:
> On Mar 19, 10:59 am, "lister" <listerofsme...@hotmail.com> wrote:
>
>
>
> > Hi all,
>
> > Is it possible to directly reference an object that is returned by a
> > function in PHP?
>
> > ie this:
> > echo ReturnAnObject()->SomeMember;
>
> > instead of this:
> > var $Object = ReturnAnObject();
> > echo $Object->SomeMember;
>
> > 'cus I can't work out the syntax if it is. :-(
>
> > Cheers,
> > Lister
>
> This code works fine for me:
>
> <?php
> class foo {
> public $bar = 'bar';
>
> }
>
> function baz() {
> return new foo();
>
> }
>
> echo baz()->bar;
> ?>
I think it only works in PHP 5+ not in PHP 4. WIth PHP 4 you have to
set it to a variable then use that variable to call the function as
you have in your OP.
Navigation:
[Reply to this message]
|