PHP:新手问题 - 在php中使用/ end的东西?

时间:2011-03-17 19:54:37

标签: php asp-classic

是否有类似于/结束(如在asp中)的PHP? 特别是对于类对象,它会很好 - asp语法就像:

with myWeb
    .init "myweb"
    response.write .html  
end with

感谢

5 个答案:

答案 0 :(得分:6)

不,PHP中没有这样的东西:当你想使用它们时,你必须写出类/对象/变量/的全名。

答案 1 :(得分:1)

不,AFAIK。

你真的觉得这个语法有用吗?

答案 2 :(得分:1)

不,但您可能感兴趣alternative syntax for control structures

答案 3 :(得分:0)

不确定我是对的,但我尽力翻译你的例子:/

<?php function write_block(){
echo '.html';
}

die(write_block());
?>

答案 4 :(得分:0)

这不完全是你想要的,但你可以用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);
?>