| |
| Recipe 2.12: Calling Methods Only if They Exist |
Last Updated: Sep 8, 2003
Status: Draft
|
|
|
|
How important is this problem to you?
(Login to Vote)
5.00 Rating, 3 Votes
|
|
How acceptable is the proposed solution?
(Login to Vote)
4.00 Rating, 2 Votes
|
|
Problem:
   
You want to call an attribute or method only if the class or object actually supports it, to avoid "no such attribute or method" errors.
Solution:
  
Use CAN:
$obj.foo if $obj.CAN.foo;
MyClass.foo if MyClass.CAN.foo;
Discussion:
|
|