note 123699 rejected from faq.using by cmb
| From: | cmb@php.net | Date: | Mon, 18 Mar 2019 14:15:37 +0000 |
| Subject: | note 123699 rejected from faq.using by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210404@lists.php.net to get a copy of this message | ||
Note Submitter: parrot dot hunters at gmail dot com
----
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