<?php
function some_func(){
return 'some_str_type' && 'another_str_type';
}
function another_func(){
return '123' || '456';
}
print some_func(); //1 - the same as true
print another_func(); //again prints 1, as true
The clean style of coding of any language dictates, to drop non-small function into small ones - because one function SHOULD return single value.
BUT, i saw this approach in source of some popular php-template langs (smarty, dwoo). So what is that? When to code this way? (mean any real-world situation)
PHP will return 1 value. What you are doing above is you type an expression, that is evaluated, and the resulting boolean is returned.
return 'some_str_type' && 'another_str_type';
becomes
return true && true;
becomes
return true;
When to use in real life:
function some_func(){
$success1 = doStuff1();
$success2 = dostuff2();
return $success1 && $success2;
}
it will return true if both called functions return true.