Hi guys,
I am a newbie in PHP, but experienced in other OOP languages, so sorry if my questions are maybe trivial for some of the forum members, but hope can get some answers for my questions.
Tried to google some info on the fact if PHP supports object casting, but could not find any useful answer, except one, but with a poor description.So is it possible in PHP to use object casting (I do not mean vasriable casting, like boolean, integer types)?
My example:
I define a class called Test with some logic, then create some objects of Test type. Then let's say I create an array of Test objects, so I can access any of the Test objects from the array by the array index. But I want to make sure that the returned array member for xy index is actually a type of Test. The logic above is maybe trivial, but I just tried to simplify what I want to achieve.
So now, how can I achieve this type of casting in PHP?The pseudocode is below:
//$ArrayList is an array of obejcts of Test type
//ArrayMember is an object, but want to make sure that it is actually of type of Test, so need an explicit casting
$ArrayMember = (Test)$ArrayList[xy];
I know that I could use the function get_class() for the array members to test whether they are of Test type, but I need to use casting rather than testing it.
Thank you
Ben