note 123699 added to faq.using

From: Date: Mon, 18 Mar 2019 12:12:05 +0000
Subject: note 123699 added to faq.using
Groups: php.notes 
Request: Send a blank email to php-notes+get-210403@lists.php.net to get a copy of this message
Hi, I have a sample code to create an object of class using ternary operator. Example: $object = (1===1)? new A() : new B(); I want to know that can we use : new A() or new B() statement in ternary operator or we should use if-else condition to create an object like: If(1===1) { $object = new A() ; } else { $object = new A(); } What will you recommend? ternary operation or if-else condition for above means which mentod is good? If you are a code reviewer then what will you suggest me 1. ternary 2. if-else (please answer should be based on above example) Thanks ---- Server IP: 208.43.231.9 Probable Submitter: 185.85.3.194 (proxied: 116.50.59.180) ---- Manual Page -- http://php.net/manual/en/faq.using.php Edit -- https://master.php.net/note/edit/123699 Del: integrated -- https://master.php.net/note/delete/123699/integrated Del: useless -- https://master.php.net/note/delete/123699/useless Del: bad code -- https://master.php.net/note/delete/123699/bad+code Del: spam -- https://master.php.net/note/delete/123699/spam Del: non-english -- https://master.php.net/note/delete/123699/non-english Del: in docs -- https://master.php.net/note/delete/123699/in+docs Del: other reasons-- https://master.php.net/note/delete/123699 Reject -- https://master.php.net/note/reject/123699 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#210403) next »