Exceptions for method on non-object rather than fatal (desired feature?)

From: Date: Tue, 21 Feb 2012 14:18:58 +0000
Subject: Exceptions for method on non-object rather than fatal (desired feature?)
Groups: php.internals 
Request: Send a blank email to internals+get-57916@lists.php.net to get a copy of this message
Hi list, I am aware this question might have been discussed to death but I did some googling on $subject and watched the bug/feature tracker and it seems most entries on this issue are old and unanswered. Is there a design decision or hard-to-overcome engine limitation which prevents turning method-on-nonobject into a catchable Exception? Or did just nobody step up and provide a patch? Rationale: In another language/framework context I did a lot of chained/nested stuff like this: $granny_name = $baby->getMother()->getMother()->getName(); In PHP I would rather do $mother = $baby->getMother(); if ($mother) {
    $granny = $mother->getMother();
    if ($granny) {
        $granny_name  = $granny->getName();
    }
} because I have no way to catch if $mother or $granny cannot be retrieved. If it's generally welcome I'll try and supply a patch. (Now let's hope this doesn't start something evil.) -- Ralf Lang Linux Consultant / Developer Mail: lang@b1-systems.de B1 Systems GmbH Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

« previous php.internals (#57916) next »