php определить тип переменной = instanceof
Primary tabs
для определения типа "на ходу" - то есть когда порядок выполнения действий записит от типа переменной можно очень даже неплохо использовать оператор instanceof - в следующем ключе =
/*
* The setRadius() function is written in the Circle class
* definition above, so make sure $item is an instance of
* type Circle BEFORE calling it AND to avoid PHP PMS!
*/
// ЕСЛИ ЭТО ОКРУЖНОСТЬ
if($item instanceof Circle)
{
$item->setRadius($i);
}
/*
* The setLocation() function is written in the Point class
* definition above, so make sure $item is an instance of
* type Point BEFORE calling it AND to stay out of the ER!
*/
// ЕСЛИ ЭТО ТОЧКА
if($item instanceof Point)
{
$item->setLocation($i, $i);
}
- Log in to post comments
- 2055 reads