2011-03-17 2 views
2

/end와 (PHP에서와 같이) PHP와 같은 것이 있습니까? 특히 클래스 은 좋은 것 객체 - ASP 구문은 같은 것입니다 :PHP : newbie 질문 - PHP에서 with/with와 (과) 비슷한 것?

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

감사

+0

합니다. –

+0

with/end는 무엇을 할 것인가? 그렇다면 내가 도울 수있을 것이다 :-D – Neal

+0

@jW와 @maniator, 기본적으로 "with object"라고 말하면서'$ obj-> variable = "something"' 그것은 "with"블록 내에있는 한'-> variable = "something"이 될 것입니다. –

답변

6

아니, 거기 PHP에서 그런 일이 없다 : 당신은 클래스/객체/변수의 전체 이름을 작성해야/그걸 언제 사용하길 원하니?

+0

명성이 PHP에 있습니다! 제 생각에는 VB의 최악의 기능 중 하나입니다. :/ –

1

아니요, AFAIK.

정말이 구문이 유용합니까?

0

하지 않도록 메신저를 잘하지만, 귀하의 예를 번역하기 위해 최선을 tryed :/

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

die(write_block()); 
?> 
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); 
?> 
+0

이 메서드의 장점은 "with"문 중첩에 대해 걱정할 필요가 없다는 것입니다. 단순한 명명 된 개체를 사용하여 원하는 비트를 참조하기 만하면됩니다. – user2679212