Layers Layers - 1 year ago 89
PHP Question

In PHP does return false bubble up?

I have a class with some methods in php.

One public method calls a protected method. If the protected method returns false will the public method return false and not continue?

public static function a() {
$class = getClass();
// some more code...

protected static function getClass() {
$classList = self::find_by_sql("
FROM ".self::$table_name."
WHERE Class_Closed = FALSE

if (empty($classList)) {
return false;
} else {
return $classList[0];

Answer Source

No. $class will have a false value but you still need to return it from YourClass::a() if you want the method to terminate and return that value immediately. return only is in scope of the function/method it is called from.

public static function a(){ 
  $class = getClass();
  if (!$class) {
      return false; // or return $class;
  some more code...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download