Weird things with the PHP Ternary Operator

$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.

2 thoughts on “Weird things with the PHP Ternary Operator

  1. 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.

Comments are closed.