|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-10-02 00:32 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
-Package: PHP Language Specification
+Package: Scripting Engine problem
[2015-10-02 00:32 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 06 06:00:01 2026 UTC |
Description: ------------ I suspect this is a bug as the behaviour is a little worrying. I was using the following in a Laravel program $fieldLabel = // has a field label been manually defined ($fieldLabel = $this->hasAttribute($fieldValue, 'FieldLabel')) ? $fieldLabel : ($this->parseFieldType($fieldValue) != 'hidden') ? ucfirst($fieldKey) : ''; However when $label was defined it was resolving to $fieldLabel = ucfirst($fieldKey); (ie. the second ternary). the resolution was to parenthesise the second ternary (which I should have done in the first place): $fieldLabel = // has a field label been manually defined ($fieldLabel = $this->hasAttribute($fieldValue, 'FieldLabel')) ? $fieldLabel : (($this->parseFieldType($fieldValue) != 'hidden') ? ucfirst($fieldKey) : ''); The bug, in my eyes, is that aforementioned code should have thrown an exception as the ternary statement gave an ambiguous result. best Jon Test script: --------------- // here is the same issue again in a simpler form, tested with // "php artisan tinker" $foo = 1; $bar = ($bar = $foo) ? $bar : ($bar = 2) ? 2 : 'null'; Expected result: ---------------- either an exception as the statement is ambiguous or 1; I would suggest the former. Actual result: -------------- 2