note 129606 added to language.operators.comparison

From: Date: Thu, 20 Jun 2024 09:38:58 +0000
Subject: note 129606 added to language.operators.comparison
Groups: php.notes 
Request: Send a blank email to php-notes+get-221392@lists.php.net to get a copy of this message
The ternary operator (aka Elvis operator) can also be used to execute multiple actions in sequence with an object that has methods whose return signature is void, as they will then. >>> ($stack = new SplStack())->push(1) ?: $stack->push(2) ?: 3 => 3 >>> $stack => SplStack {#2717 mode: IT_MODE_LIFO | IT_MODE_KEEP, dllist: [ 1 => 2, 0 => 1, ], } That can also help to chain calls to setters in a callback used in a fluent interface such as Laravel’s Illuminate\Support\Collection. ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.137 (proxied: 2a01:e0a:9a5:f7b0:798d:e40:170b:88b1) ---- Manual Page -- https://php.net/manual/en/language.operators.comparison.php Edit -- https://main.php.net/note/edit/129606 Del: integrated -- https://main.php.net/note/delete/129606/integrated Del: useless -- https://main.php.net/note/delete/129606/useless Del: bad code -- https://main.php.net/note/delete/129606/bad+code Del: spam -- https://main.php.net/note/delete/129606/spam Del: non-english -- https://main.php.net/note/delete/129606/non-english Del: in docs -- https://main.php.net/note/delete/129606/in+docs Del: other reasons-- https://main.php.net/note/delete/129606 Reject -- https://main.php.net/note/reject/129606 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221392) next »