Carlos Rodrigues <carlos.v...@gmail.com> wrote:
>So instead of writing
>if ($obj->image) {
>echo $obj->image->getUrl();
>}
>
>He wrote:
>echo $obj->image->getUrl();

Make the property private and add a getter which can throw an exception if no 
image is available ...

class C {
    private $image;
    public function hasImage() { return (bool)$this->image; }
    public function getImage() { if (!$this->image) { throw new 
NoImageException(); } return $this->image; }
}
echo $obj->geImage()->getUrl(); // Exception which can be caught.

No nee dto change the language and add a new cosntruct (which your developer 
will forget, if he forgets the if already ....)

johannes

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to