How do I use global namespace type hinting inside of a namespaced class in PHP 5.3+? -


namespace myclass\util;  class sample {    public function each(object $f) {    } } 

from calling file (not namespaced)

$sample = new sample(); $sample->each(new stdclass()); 

produces:

catchable fatal error: argument 1 passed myclass\util\sample.php must instance of myclass\util\object, instance of object given

you can use \ point global namespace :

namespace myclass\util;  class sample {    public function each(\object $f) {    } } 


reference, can read global space (quoting) :

prefixing name \ specify name required global space in context of namespace.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -