Re: Why is some_function()[some_index] invalid syntax?
| From: | Zoltán Németh | Date: | Fri, 11 Jan 2008 08:45:50 +0000 |
| Subject: | Re: Why is some_function()[some_index] invalid syntax? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-267068@lists.php.net to get a copy of this message | ||
2008. 01. 10, csütörtök keltezéssel 21.25-kor Jim Lucas ezt írta:
> Nathan Nobbe wrote:
> > On Jan 10, 2008 11:00 PM, Arlen Christian Mart Cuss <celtic@sairyx.org>
> > wrote:
> >
> >> Hi there,
> >>
> >> Why is it that if I try to evaluate an index of an array returned by a
> >> function immediately, a syntax error is produced? (unexpected '[',
> >> expecting ',' or ';')
> >
> >
> > thats hillarious, i literally brought this up at the office like 2 days ago.
> > ill tell you why its really lame (imho), because php5 supports syntax
> > like this:
> > function someFunc() {
> > return date_create();
> > }
> > echo someFunc()->format('Y-m-d');
> >
> > that is, it allows you to chain a method invocation to the invocation of a
> > function
> > if the function returns an object.
> >
> > -nathan
> >
>
> So, make all your functions return objects, and have the object have a
> method called get or index or something like that that returns the index
> requested. :)
>
> Better yet, make everything an object: String, Numeric, Array, etc
and call it Java ;)
greets
Zoltán Németh
>