PHP Encapsulation Surprises PHP encapsulamento surpresas
In PHP, unlike Java or C++, $this has to be explicitly used to refer to variables within a class. Em PHP, ao contrário de Java ou C + +, $ esta tem de ser explicitamente utilizado para se referir a variáveis dentro de uma classe.
The value of $this is determined by the context in which it is called. O valor de US $ este é determinado pelo contexto em que é chamado. In certain situations $this may actually refer to the invoking class rather then the current class. Em certas situações isto pode realmente dólares referem-se a invocar a classe em vez de a actual classe. This breaks object encapsulation. Esta quebra objeto encapsulamento.
$this pseudo-variable is not defined if the method in which it is located is called statically with an exception as noted below. $ esta pseudo-variável não está definido se o método em que está localizada é chamada estaticamente com uma excepção, tal como descritos a seguir.
$this is defined if a method is called statically from within another object. $ este é definido se um método é chamado estaticamente dentro de outro objeto. In this case, the value of $this is that of the calling object. Neste caso, o valor de US $ trata-se de que a chamada objeto.
The following example from PHP manual will clarify this: O exemplo a seguir a partir de PHP manual irá esclarecer o seguinte:
foo(); A::foo(); $b = new B(); $b->bar(); B::bar(); ?> foo (); R:: foo (); $ b = new B (); $ b-> bar (); B:: bar ();?> Output: Saída:
$this is defined (a) $ este é definido (a)
$this is not defined. $ este não é definido.
$this is defined (b) $ este é definido (b)
$this is not defined. $ este não é definido.
Filed under Arquivado em Headline News Headline News , Java Software Java Software , PHP , Web | |
| |
RSS 2.0 RSS 2,0 | |
Trackback this Article | este artigo |
Email this Article E-mail este artigo
You may also like to read Você pode também gosta de ler |



































