PHP:新手问题-类似于PHP中的with/end with?
php是否有类似于with/end with(类似于asp)的东西? 特别是对于类对象,这会很好-asp语法如下:PHP:新手问题-类似于PHP中的with/end with?,php,asp-classic,Php,Asp Classic,php是否有类似于with/end with(类似于asp)的东西? 特别是对于类对象,这会很好-asp语法如下: with myWeb .init "myweb" response.write .html end with 谢谢不,PHP中没有这样的东西:当你想使用类/对象/变量/任何东西时,你必须写它们的全名。不,好的 你真的觉得这个语法有用吗?我不确定我是否正确,但我尽力翻译了你的例子:/ <?php function write_block(){ echo '
with myWeb
.init "myweb"
response.write .html
end with
谢谢不,PHP中没有这样的东西:当你想使用类/对象/变量/任何东西时,你必须写它们的全名。不,好的
你真的觉得这个语法有用吗?我不确定我是否正确,但我尽力翻译了你的例子:/
<?php function write_block(){
echo '.html';
}
die(write_block());
?>
没有,但是有一个问题可能会引起您的兴趣。这并不是您想要的,但是您可以对PHP引用执行类似的操作:
<?php
class A {
public $bar1 = 1;
public $bar2 = 2;
public $bar3 = 3;
}
class B {
public $foo;
}
class C {
public $foobar;
}
$myC = new C;
$myC->foobar = new B;
$myC->foobar->foo = new A;
print $myC->foobar->foo->bar1;
print $myC->foobar->foo->bar2;
print $myC->foobar->foo->bar3;
//Simpler with 'With...End With syntax:
//which might look something like:
//
// with ($myC->foobar->foo) //Note this is not valid PHP
// {
// print ->bar1; //Note this is not valid PHP
// print ->bar2; //Note this is not valid PHP
// print ->bar3; //Note this is not valid PHP
// }
//
//Fortunately, you can sort of do this using an object reference:
//
$obj =& $myC->foobar->foo;
print $obj->bar1;
print $obj->bar2;
print $obj->bar3;
unset ($obj);
?>
如果您能解释with/end结构的作用,可能会有所帮助。with/end结构的作用是什么,那么我可以提供帮助:-D@jW和@maniator,基本上你说“with object”,然后不用输入$obj->variable=“something”
,只要它在“with”范围内,它就会是->variable=“something”
不确定,但我认为end就像die,end会触发objectKudos到PHP!在我看来,VB最糟糕的特性之一是:/这种方法的优点是,您不需要担心嵌套“with”语句,因为您只需要使用简化的命名对象来引用所需的位。