2
return (empty($neededRole) || strcasecmp($role, 'admin') == 0 || strcasecmp($role, $neededRole) == 0);

What exactly does the || mean in this statement? Can someone put this in english for me.

I promise I've googled this but I guess I don't know what to google for because I can't find anything.

thanks:)

Gordon
  • 312,688
  • 75
  • 539
  • 559
BPD
  • 71
  • 1
  • 1
  • 8
  • http://stackoverflow.com/questions/5662242/can-someone-please-put-this-in-english-for-me-php-cakephp – Nabeel Apr 14 '11 at 16:57
  • *(related)* [What does that symbol mean in PHP](http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php) – Gordon Apr 14 '11 at 17:46
  • -1 You should really review some programming basics. You won't code anything good in PHP if you even ignore the **very** basics of programming :( I'm very sorry to tell you this. – gd1 Apr 14 '11 at 18:59

4 Answers4

3

It is the OR logicial operator.

http://www.php.net/manual/en/language.operators.logical.php

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
2

Googling symbols is always hard. Don't worry: || means or in the statement. Don't confuse it for Xor which is slightly different:

  • or or || is meant as A or B or A + B
  • xor is meant as A or B, not both

References:

Shoe
  • 74,840
  • 36
  • 166
  • 272
0

This is an OR operator. It is true if any of it's 'parameters' is true.

Dr McKay
  • 2,548
  • 2
  • 21
  • 26
  • Hummm... now I'm even more confused. I thought it would at least return a value, ie admin or user. If I give you the full function would you look at it and tell me what exactly it would return? I'll stick it in the next comment – BPD Apr 14 '11 at 17:31
  • public function isAuthorized() { $role = $this->Auth->user('role'); $neededRole = null; $prefix = !empty($this->params['prefix']) ? $this->params['prefix'] : null; if (!empty($prefix) && in_array($prefix, Configure::read('Routing.prefixes'))) { $neededRole = $prefix; } return (empty($neededRole) || strcasecmp($role, 'admin') == 0 || strcasecmp($role, $neededRole) == 0); } – BPD Apr 14 '11 at 17:32
  • Do I look like a parser? Would you at least format your code? Code in your question will probably return if user is admin or user. What I meant in my answer is: if any of OR operands if true, operator returns true, false otherwise. – Dr McKay Apr 14 '11 at 17:52
  • Thanks Dr McKay, I appreciate your help. And sorry about the code. I can't figure out how to do a carriage return without posting a whole new comment! – BPD Apr 14 '11 at 21:25
0

|| means or. It's a logical or, so it's true if at least one of the terms is true, false otherwise.

KJYe.Name
  • 16,969
  • 5
  • 48
  • 63
boisvert
  • 3,679
  • 2
  • 27
  • 53