Re: [PHP] object literals

2009-05-03 Thread Richard Heyes
> i'm really lazy about typing. I think every good programmer is... ;-) -- Richard Heyes HTML5 graphing: RGraph (www.rgraph.net) PHP mail: RMail (www.phpguru.org/rmail) PHP datagrid: RGrid (www.phpguru.org/rgrid) PHP Template: RTemplate (www.phpguru.org/rtemplate) -- PHP General Mailing List (

Re: [PHP] object literals

2009-05-02 Thread Tom Worster
On 5/2/09 6:45 AM, "Robert Cummings" wrote: > It's not what I want, I'm not the original poster. as op, i think i'm going to stick with the cast. but it's been an interesting thread and i learned some useful things. > Regardless though, it > comes down to the preference of the developer. It ca

RE: [PHP] object literals

2009-05-02 Thread Robert Cummings
On Sat, 2009-05-02 at 12:10 +0100, Ashley Sheridan wrote: > On Sat, 2009-05-02 at 06:45 -0400, Robert Cummings wrote: > > On Sat, 2009-05-02 at 12:39 +0200, Andrea Giammarchi wrote: > > > exactly, why bother with JavaScript literal representation? > > > > > > the foreach loop was just an alternat

RE: [PHP] object literals

2009-05-02 Thread Ashley Sheridan
On Sat, 2009-05-02 at 06:45 -0400, Robert Cummings wrote: > On Sat, 2009-05-02 at 12:39 +0200, Andrea Giammarchi wrote: > > exactly, why bother with JavaScript literal representation? > > > > the foreach loop was just an alternative to explicit object cast cause you > > did not like it I th

RE: [PHP] object literals

2009-05-02 Thread Robert Cummings
On Sat, 2009-05-02 at 12:39 +0200, Andrea Giammarchi wrote: > exactly, why bother with JavaScript literal representation? > > the foreach loop was just an alternative to explicit object cast cause you > did not like it I though it was more about control over what you want to > cast and what

RE: [PHP] object literals

2009-05-02 Thread Andrea Giammarchi
php you have natural type hint over arrays and these are normally slightly faster so I do not get why you want objects rather than arrays ... > Subject: RE: [PHP] object literals > From: rob...@interjinn.com > To: an_...@hotmail.com > CC: f...@thefsb.org; php-general@lists.php.net &g

RE: [PHP] object literals

2009-05-01 Thread Robert Cummings
On Fri, 2009-05-01 at 17:52 +0200, Andrea Giammarchi wrote: > you are in PHP, not in JavaScript. > > In PHP arrays are like collections or hash tables. > if you strictly need object cause > > $o->stuff > is better than > $o['stuff'] > > having exactly the same number of characters, you can creat

RE: [PHP] object literals

2009-05-01 Thread Andrea Giammarchi
ooops sorry, two more ;-) > having exactly the same number of characterss.aspx _ Windows Live™: Keep your life in sync. Check it out! http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009

RE: [PHP] object literals

2009-05-01 Thread Andrea Giammarchi
ray { // no way } Regards > From: rob...@interjinn.com > To: an_...@hotmail.com > CC: f...@thefsb.org; php-general@lists.php.net > Date: Fri, 1 May 2009 11:40:11 -0400 > Subject: RE: [PHP] object literals > > On Fri, 2009-05-01 at 17:36 +0200, Andrea Giammarchi wrote: >

RE: [PHP] object literals

2009-05-01 Thread Robert Cummings
On Fri, 2009-05-01 at 17:36 +0200, Andrea Giammarchi wrote: > var o = { > "a" : "b", > "c" : "d" > }; > > $o = array( > 'a' => "b", > 'c' => "d" > ); > > so I guess the problem is a couple of quotes, isn't it? > > > otherwise define object statically and externally and use json_

RE: [PHP] object literals

2009-05-01 Thread Andrea Giammarchi
se json_decode ;-) > Date: Thu, 30 Apr 2009 16:56:21 -0400 > From: f...@thefsb.org > To: php-general@lists.php.net > Subject: [PHP] object literals > > is there a neat literal syntax for creating objects on the fly without > defining a type? > > whenever i need to do

Re: [PHP] object literals

2009-05-01 Thread Tom Worster
On 5/1/09 4:54 AM, "Richard Heyes" wrote: > Hi, > >>    $x = (object) array('a'=>1, 'b'=>3, ...); >> >> which works but isn't very lovely. it's neater in, for example, javascript. > > Well, you could wrap it up in a function to make it a bit lovelier. Eg: > > $foo = createObject(array('key' =

Re: [PHP] object literals

2009-05-01 Thread Richard Heyes
Hi, > You could use JSON, > > $foo = json_decode('{"a":1,"b":3}'); > > but I guess that's not much better than Richard's suggestion. Didn't think of that (well... it's new). That's actually much better I think, since you get the added boon of ease of portability to JS (if that's even a factor).

Re: [PHP] object literals

2009-05-01 Thread Peter Ford
Richard Heyes wrote: > Hi, > >>$x = (object) array('a'=>1, 'b'=>3, ...); >> >> which works but isn't very lovely. it's neater in, for example, javascript. > > Well, you could wrap it up in a function to make it a bit lovelier. Eg: > > $foo = createObject(array('key' => 'value')); > > It's n

Re: [PHP] object literals

2009-05-01 Thread Richard Heyes
Hi, >    $x = (object) array('a'=>1, 'b'=>3, ...); > > which works but isn't very lovely. it's neater in, for example, javascript. Well, you could wrap it up in a function to make it a bit lovelier. Eg: $foo = createObject(array('key' => 'value')); It's not great, but PHP doesn't have a object

[PHP] object literals

2009-04-30 Thread Tom Worster
is there a neat literal syntax for creating objects on the fly without defining a type? whenever i need to do it i do something like $x = (object) array('a'=>1, 'b'=>3, ...); which works but isn't very lovely. it's neater in, for example, javascript. -- PHP General Mailing List (http://w