Lack of: with (object) {...} in PHP
Posted: Thu Jul 05, 2007 12:24 pm
In Delphi and JavaScript, we can avoid of typing an object's name by using the with { ... } statements.
Is this possible in PHP as you see in "Sample B" below?
Sample A:
Sample B: Re-written using a with-like statement:
As you see, there will be some benefits with a with-like statement. Is this possible?
Is this possible in PHP as you see in "Sample B" below?
Sample A:
Code: Select all
$i = 0;
$catArr[] = array();
while ($rs = mysql_fetch_array($db_result))
{
$catArr[$i] = new Cat();
$catArr[$i]->setCatID();
$catArr[$i]->setName($rs['CatID']);
$catArr[$i]->setGender($rs['Gender']);
$catArr[$i]->setAge($rs['Age']);
$catArr[$i]->setBreed($rs['Brred']);
$i++;
}Code: Select all
$catArr = array();
while ($rs = mysql_fetch_array($db_result)) {
with ($catArr[] = new Cat()) {
setCatID();
setName($rs['CatID']);
setGender($rs['Gender']);
setAge($rs['Age']);
setBreed($rs['Brred']);
}
}