0

I found this piece of code that I did not write:

$serverArray['msg'] = $data_log['AuthLog']['response_text'] = ($outputArray['transOutput']['outputCode'] == 1) ? $outputArray['transOutput']['msg'][0]['desc'] : $outputArray['transOutput']['errors'][0]['errorText'];

As you can see in the code about, the = sign appears twice in the same line (ignoring == because that is clear to me what it means. In other words, I am trying to understand if the line of code is doing one of these two versions:

  1. $serverArray['msg'] = $data_log['AuthLog']['response_text'];
  2. $serverArray['msg'] = ($outputArray['transOutput']['outputCode'] == 1) ? $outputArray['transOutput']['msg'][0]['desc'] : $outputArray['transOutput']['errors'][0]['errorText'];

I guess what the code does is not simply limited to one of the two versions above because if that were the case, it would have been written exactly as one of the two versions above and it was not. So what is the usage of two = signs in the same line of code? Thanks.

Jaime Montoya
  • 6,915
  • 14
  • 67
  • 103
  • 2
    a = b = c = 1 -> a =1, b = 1, c = 1. – Michael Chourdakis Dec 21 '18 at 20:23
  • 1
    `$serverArray['msg']` and `$data_log['AuthLog']['response_text']` will be set to `($outputArray['transOutput']['outputCode'] == 1) ? $outputArray['transOutput']['msg'][0]['desc'] : $outputArray['transOutput']['errors'][0]['errorText']`, because `=` operator's return value is the right side of the assignment. So `$a=$b=$c` is equals to `$a=$c; $b=$c` – FZs Dec 21 '18 at 20:36
  • @FZs Clear and concise! Please write this as an answer for me to accept it and have this question as resolved. – Jaime Montoya Dec 21 '18 at 20:38
  • 1
    @JaimeMontoya The question is closed, so I can't answer. – FZs Dec 21 '18 at 20:39
  • @FZs I can see that, but thank you for your help! – Jaime Montoya Dec 21 '18 at 20:54
  • 1
    You should find the person that wrote that line and beat them with a sack of oranges until they apologize. – Sammitch Dec 21 '18 at 20:55
  • @Sammitch Hahaha. It was not a problem to have two `=` signs in a single line of PHP code. That is totally fine and proper PHP code. I still found a bug in that line but that is another topic, so I will not beat them with a sack of oranges. I will use potatoes instead. Just kidding. – Jaime Montoya Dec 22 '18 at 23:03
  • 1
    It's not that the line isn't valid code [sans bug] it's just needlessly cramming together too much into one line, making it difficult to read, maintain, and debug. – Sammitch Dec 22 '18 at 23:06
  • @Sammitch You are right. – Jaime Montoya Dec 23 '18 at 02:50

0 Answers0