Re: Ternary operator performance improvements
| From: | Arnaud Le Blanc | Date: | Tue, 18 Oct 2011 20:09:37 +0000 |
| Subject: | Re: Ternary operator performance improvements | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-55861@lists.php.net to get a copy of this message | ||
Hi,
Le Monday 17 October 2011 15:07:30, Alain Williams a écrit :
> On Fri, Oct 14, 2011 at 08:08:56PM +0200, Arnaud Le Blanc wrote:
> > Hi,
> >
> > I've already posted this patch and it has since been reviewed and
> > improved. I'm re-posting it for discussion before eventually commiting
> > it.
> >
> > The ternary operator always copies its second or third operand, which is
> > very
>
> > slow compared to an if/else when the operand is an array for example:
> Is that why the following does not work as I expected:
>
> $dbh = $how == 'r' ? (&$dbh_r) : (&$dbh_w);
>
> $dbh is NOT a reference to $dbh_r or $dbh_w.
This is expected;
http://docs.php.net/manual/en/language.operators.comparison.php
explains it:
> Please note that the ternary operator is a statement, and that it doesn't
evaluate to a variable, but to the result of a statement.
This is why you can't assign the result of the ternary operator by reference.
The patch doesn't change this.
Best regards,