mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-14 17:54:06 +02:00
Merge pull request #602 from echernyavskiy/patch-2
Add an example of even more simple boolean return statement
This commit is contained in:
@@ -27,7 +27,7 @@ if (strpos('testing', 'test')) { // 'test' is found at position 0, which is i
|
|||||||
// code...
|
// code...
|
||||||
}
|
}
|
||||||
|
|
||||||
// vs
|
// vs.
|
||||||
|
|
||||||
if (strpos('testing', 'test') !== false) { // true, as strict comparison was made (0 !== false)
|
if (strpos('testing', 'test') !== false) { // true, as strict comparison was made (0 !== false)
|
||||||
// code...
|
// code...
|
||||||
@@ -57,7 +57,7 @@ function test($a)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// vs
|
// vs.
|
||||||
|
|
||||||
function test($a)
|
function test($a)
|
||||||
{
|
{
|
||||||
@@ -66,6 +66,14 @@ function test($a)
|
|||||||
}
|
}
|
||||||
return false; // else is not necessary
|
return false; // else is not necessary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// or even shorter:
|
||||||
|
|
||||||
|
function test($a)
|
||||||
|
{
|
||||||
|
return (bool) $a;
|
||||||
|
}
|
||||||
|
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
|
||||||
* [If statements](http://php.net/control-structures.if)
|
* [If statements](http://php.net/control-structures.if)
|
||||||
|
Reference in New Issue
Block a user