? Success

User tests: Successful: Unsuccessful:

avatar Kubik-Rubik Kubik-Rubik - open - 16 Apr 2014
avatar Kubik-Rubik Kubik-Rubik - change - 16 Apr 2014
Title
Expression is not assignable: Infix expression
[#33624] Expression is not assignable: Infix expression
avatar zero-24
zero-24 - comment - 16 Apr 2014

@Kubik-Rubik
Is there a good way to test it? Or a case that show a error?
The Patch looks good for me :+1:

Here is a backport to 2.5: #3466

avatar zero-24 zero-24 - reference | - 16 Apr 14
avatar Kubik-Rubik
Kubik-Rubik - comment - 17 Apr 2014

Actually, you can not test it. It is more a coding standard problem. The Not operator (!) has a higher precedence then the Assignment operator (=). See the operator precedence list for more information: http://www.php.net/manual/en/language.operators.precedence.php

avatar Bakual
Bakual - comment - 17 Apr 2014

Viktor is right that it's not the best codestyle. However PHP makes it work neverthless :smiley:
From the note on the page linked:

Although = has a lower precedence than most other operators, PHP will still allow expressions similar to the following: if (!$a = foo()), in which case the return value of foo() is put into $a.

Which means, it's valid code. But adding the brackets would improve readability and be "cleaner" code.
I'm not aware that we have a codestyle rule for that currently, so maybe we want to add that to our rules.

avatar javigomez
javigomez - comment - 17 Apr 2014

+1 for merge it.

avatar Bakual Bakual - reference | - 17 Apr 14
avatar Bakual Bakual - close - 17 Apr 2014
avatar Bakual
Bakual - comment - 17 Apr 2014

Merged, thanks!

avatar Bakual Bakual - change - 17 Apr 2014
Title
Expression is not assignable: Infix expression
[#33624] Expression is not assignable: Infix expression
Status New Closed
Closed_Date 0000-00-00 00:00:00 2014-04-17 11:44:46
Labels Added: ? ?
avatar Bakual Bakual - close - 17 Apr 2014
avatar Bakual Bakual - reopen - 17 Apr 2014
avatar Bakual Bakual - change - 17 Apr 2014
Status Closed New
avatar Bakual Bakual - reopen - 17 Apr 2014
avatar Bakual Bakual - close - 17 Apr 2014
avatar Bakual Bakual - change - 17 Apr 2014
Status New Closed
Closed_Date 2014-04-17 11:44:46 2014-04-17 11:50:04
avatar Bakual Bakual - close - 17 Apr 2014
avatar Bakual
Bakual - comment - 17 Apr 2014

Now for real...

avatar beat
beat - comment - 17 Apr 2014

This one should really have become 2 lines. It's just calling for future trouble. Assignments should not be made in ifs.

avatar Kubik-Rubik
Kubik-Rubik - comment - 17 Apr 2014

@beat Yes, agree. I also don't like assignments in if statements.

avatar elkuku
elkuku - comment - 17 Apr 2014

I also don't like assignments in if statements.

So why not fix it the right way and avoid those assignment in condition ?

avatar Kubik-Rubik
Kubik-Rubik - comment - 17 Apr 2014

@elkuku Yes, should be done for the whole code...

avatar wilsonge wilsonge - reference | - 23 Apr 14
avatar Bakual Bakual - reference | 1a6e4f2 - 12 May 14
avatar Kubik-Rubik Kubik-Rubik - reference | b9e54a2 - 4 Jun 14
avatar Kubik-Rubik Kubik-Rubik - head_ref_deleted - 4 Jun 2014

Add a Comment

Login with GitHub to post a comment