note 103729 modified in language.oop5.typehinting by danbrown
| From: | danbrown@php.net | Date: | Sat, 30 Apr 2011 16:28:15 +0000 |
| Subject: | note 103729 modified in language.oop5.typehinting by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-179312@lists.php.net to get a copy of this message | ||
i use eclipse ganymede as an IDE and it offers "intellisense" where it can, i.e. when
variables are "declared" via type hinting or a "new"-statement . i found using
the following pattern helps eclipse along as well:
<?php
class MyClass{
public static function Cast(MyClass &$object=NULL){
return $object;
}
public method CallMe(){
}
}
$x=unserialize($someContent);
$x=MyObject::Cast($x);
$x->CallMe();
?>
after calling Cast(), due to the type hinting, eclipse offers me the "CallMe" function in
a dropdown when i type "$x->" in the code afterwards.
i found this very practical und included the Cast() function in my code template for new classes.
i've been wondering, if there is a drawback i oversaw, but i haven't noticed any negative
effects so far... maybe some of you will find this just as handy as i do ;o)
p.s. do note: when used in inherited classes a STRICT-notice comes up, because the function
definition of the inherited class doesn't match the parent's definition (different type
hinting) - but it works great!
--was--
i use eclipse ganymede as an IDE and it offers "intellisense" where it can, i.e. when
variables are "declared" via type hinting or a "new"-statement . i found using
the following pattern helps eclipse along as well:
class MyClass{
public static function Cast(MyClass &$object=NULL){
return $object;
}
public method CallMe(){
}
}
$x=unserialize($someContent);
$x=MyObject::Cast($x);
$x->CallMe();
after calling Cast(), due to the type hinting, eclipse offers me the "CallMe" function in
a dropdown when i type "$x->" in the code afterwards.
i found this very practical und included the Cast() function in my code template for new classes.
i've been wondering, if there is a drawback i oversaw, but i haven't noticed any negative
effects so far... maybe some of you will find this just as handy as i do ;o)
p.s. do note: when used in inherited classes a STRICT-notice comes up, because the function
definition of the inherited class doesn't match the parent's definition (different type
hinting) - but it works great!
http://php.net/manual/en/language.oop5.typehinting.php