Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!

Timeline for answer to Hidden Features of PHP? by Dean

Current License: CC BY-SA 2.5

Post Revisions

21 events
when toggle format what by license comment
Dec 7, 2010 at 0:25 comment added Matti Virkkunen I can't begin to fathom why @brianreavis's comment has 23 upvotes even though he's fundamentally misunderstood variable interpolation in strings...
Nov 18, 2010 at 19:47 comment added Harold1983- don't use $person[name]... if you set error_reporting to E_ALL, you will see that the compiler throws a notice. Always quote string array keys: $person['name']
Apr 10, 2010 at 3:04 comment added thomasrutter @brianreavis and @Frank Farmer that's not the case. With no curly braces inside the string, PHP treats what's in the braces as literal. eg: "$person[name]" is equivalent to "{$person['name']}" - PHP won't consider name to refer to a constant in either case. See Types -> Strings, under "Variable parsing" in the PHP manual.
Apr 10, 2010 at 2:59 comment added thomasrutter @Adam Backstrom whoa, that is an object literal in PHP! You've just blown my mind.
Feb 23, 2010 at 21:15 comment added Frank Farmer @Willi Schönborn: sure, the performance aspect may not really matter, but considering the fact that an E_NOTICE is thrown every time PHP encounters one of those, it's just plain sloppy.
Jan 29, 2010 at 10:17 comment added Talvi Watia Both using arrays AND standard class is helpful for different things.
Dec 21, 2009 at 13:31 comment added whiskeysierra Don't care about performance, readability is (way!) more important.
Sep 3, 2009 at 3:59 comment added brianreavis @majelbstoat: Taking out the quotes would slow the script down because the PHP interpreter will look to see if 'name' and 'age' have been set with define(...). It's also a bad practice considering it'd be possible to totally flip the keys that are accessed in each case: define('age','name'); define('name','age');
Jul 9, 2009 at 15:17 history edited Allain Lalonde CC BY-SA 2.5
new keyword is not allowed before array creation
Jun 6, 2009 at 21:46 comment added user7675 While we're on the subject: (object)array("name" => 'bob', 'age' => 5)
May 10, 2009 at 2:00 comment added Daniel $string = sprintf("%s is %d years old.", $person['name'], $person['age']);
May 1, 2009 at 8:20 history made wiki Post Made Community Wiki
Mar 20, 2009 at 9:58 comment added thomasrutter @Dean if you don't use curly braces, no it doesn't complain. The [ has to immediately follow the variable name, then its contents are interpreted as a string.
Mar 20, 2009 at 9:56 comment added thomasrutter Makes it very Javascript-y :)
Nov 24, 2008 at 12:59 comment added Dean Rather I didn't know that one. It doesn't complain that it has to assume you're not using undefined constants?
Nov 24, 2008 at 1:44 comment added majelbstoat "person[name] is $person[age] years old" will also work... No quotes, no braces :)
Nov 17, 2008 at 4:49 comment added Dean Rather You should post that as a hidden feature, I'd vote it up :)
Nov 17, 2008 at 4:48 history edited Dean Rather CC BY-SA 2.5
added 4 characters in body
Nov 16, 2008 at 23:56 comment added Kornel "{$person['name']} is {$person['age']} years old" works.
Nov 8, 2008 at 0:00 history edited Dean Rather CC BY-SA 2.5
added 237 characters in body
Nov 1, 2008 at 7:42 history answered Dean Rather CC BY-SA 2.5