Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy. This forum is not for asking programming related questions.
class cat
{
}
class dog
{
}
function cats_only(cat $xyx)
{
}
$jess=new cat();
$rover=new dog();
cats_only($jess); // works
cats_only($rover); //epic fail
class cat
{
}
class dog
{
}
function cats_only(cat $xyx)
{
}
$jess=new cat();
$rover=new dog();
cats_only($jess); // works
cats_only($rover); //epic fail
That's not type-casting and is misleading. It's type-hinting.
Type-casting is taking something that's one type and making it behave like it's another. The types must be compatible though.
PHP can also only type-cast between it's own primitive types, it can't type-cast say Cat to Animal and Vice-versa if you have those classes.
Chris Corbyn wrote:PHP can also only type-cast between it's own primitive types, it can't type-cast say Cat to Animal and Vice-versa if you have those classes.
And just for the record you don't need to since PHP is dynamically typed ( I know you know that Chris but posting for OP )