About Me: Jawaad Mahmood: 30, Muslim, Canadian, freelance, doing consulting in Tokyo, Japan.

Weird things with the PHP Ternary Operator

March 27, 2009

$amenities = $amenities = AmenityOutput::generate_list_output($object->get_amenities()) ? $amenities : “None available”;

Yes, that apparently is valid PHP.   :sick:

I switched it to this:

$amenities = AmenityOutput::generate_list_output($object->get_amenities());
if (!$amenities)  $amenities = “None available”;

Sometimes people are too clever.

Comments (2)

2 Responses to “Weird things with the PHP Ternary Operator”

  1. Kal says:

    The ugliness of this piece of code combined with the fact that it actually works, the whole idea is so wrong that it’s not even funny. Yet the PHP inventors expect people to accept this parsing behaviour. It’s as though the PHP interpreter is allowed to parse at arbitrary greediness. “Thanks for the inconsistency, you PHP fucktards.”

    Another reason for me to stay away from PHP.

  2. [...] my friend Jawaad showed me an interesting piece of ugly PHP code. I reiterated the fact that PHP sucks and that it remains trolling the web application development [...]


Archives 
August 2010 July 2010 May 2010 April 2010 March 2010 February 2010 January 2010 December 2009 November 2009 October 2009 August 2009 July 2009 June 2009 May 2009 April 2009 March 2009 February 2009 January 2009 December 2008 November 2008 August 2008 July 2008 June 2008 May 2008 April 2008 March 2008 February 2008 January 2008 December 2007 November 2007 October 2007 July 2007 June 2007 May 2007 April 2007 March 2007 February 2007 January 2007 December 2006 November 2006 October 2006 September 2006 August 2006 July 2006 June 2006 May 2006 April 2006 March 2006 February 2006 January 2006 December 2005 November 2005 February 2005 December 2004 November 2004 October 2004 September 2004

Creative Commons License
All text and images under 1024 x 768 pixels on this site are licensed under a Creative Commons Attribution 3.0 Unported License.
I require a link back to the original page of the article/image. If the image/article
is not public (IE: It is not present in an article on the blog), you may not reproduce it without permission.