Is there a possibility use "data types" in php?
I have class Page, it has variables (I use public, I don't need private in my case, there is no security risk, etc.). I create some Objects of my class add them to array, then I go trought them by foreach and I wanna use iterated object in foreach like my Page object. So I wanna let know my ide (PhpStorm) know that the object from array is type of Page, so he can whisper me his variables.
In Java I would do something like this (Page) myObject. Than the ide know "Juhuu programmer say, that myObject should be type of Page, so I let him to work him like with Page object not just like some general object"
Code bellow should explain more my problem:
NOTE:
I know that I can write inside foreach page->$url; and it will works. But how the hell I should remember all names of variables. More likely I don't want to remember them or have to find them, I want them whispered.
class Page {
public $url;
public $array_of_titles;
//...
function __construct($url,$tit) {
$this->url = $url;
$this->array_of_titles = $tit;
}
}
$array_of_pages = array();
$url = "http://..."
$tit = {"aaa", "bbb", "ccc"}
$page = new Page($url, $tit);
$array_of_pages[] = $page;
//... add more pages to the array
foreach($array_of_pages as $page) {
$my_url = $page->url; //this words but don't whisper obviously
//because in $page could by any object
//$my_url = (Page)$page->url; //this I would do in java to say
//"Hey $page is typeof Page man, I wanna whisper its methods"
}