I am trying to use is_callable
to check for class and method existence, it goes very well but keeps displaying my include parameters.
Here is the code:
if(!is_callable(array(self::$classy,self::$action))) {
self::$classy = 'index';
self::$action = 'index';
}
and here is the result:
.开发者_如何转开发;C:\php5\pear;./lib;./model;./helper;./controller;/model/;/helper/;/controller/;/lib.
This happens only if the return value is true which means the method is not callable or the class is not in the registered autoloadeds.
Any Ideas ???
You say you're checking for the existence of classes and methods.. So my first question would be, can't you use class_exists();
and method_exists();
for this?
- http://php.net/manual/en/function.class-exists.php
- http://php.net/manual/en/function.method-exists.php
Another idea for requiring certain methods on a class, would be to use interfaces. Then you'd only need to make sure the class exists, and PHP should give some messages if the methods that you've defined in your interface aren't available in said class.
- http://php.net/manual/en/language.oop5.interfaces.php
That should do the trick:
ob_start(); //activate outputbuffering (prevents the server from sending anything to the client)
if(!is_callable(array(self::$classy,self::$action))) {
self::$classy = 'index'; self::$action = 'index';
}
ob_end_clean(); //end outputbuffering and discard any output that was generated
精彩评论