In PHP, unlike Java or C++, $this has to be explicitly used to refer to variables within a class. En PHP, a diferencia de Java o C + +, $ esto tiene que ser explícitamente utiliza para referirse a las variables dentro de una clase.

The value of $this is determined by the context in which it is called. El valor de $ esto es determinado por el contexto en el que se llama. In certain situations $this may actually refer to the invoking class rather then the current class. En ciertas situaciones de dólares en realidad esto puede referirse a la invocación de clase en lugar de la actual clase. This breaks object encapsulation. Esto rompe la encapsulación objeto.

$this pseudo-variable is not defined if the method in which it is located is called statically with an exception as noted below. $ este pseudo-variable no está definida si el método en el que se encuentra se llama estáticamente con una excepción como se señala más adelante.

$this is defined if a method is called statically from within another object. de dólares este se define si un método es llamado estáticamente dentro de otro objeto. In this case, the value of $this is that of the calling object. En este caso, el valor de $ esto es que la llamada de objeto.

The following example from PHP manual will clarify this: El siguiente ejemplo de manual de PHP se aclarará esto:

 foo(); A::foo(); $b = new B(); $b->bar(); B::bar(); ?> foo (); A:: foo (); $ b = new B (); $ b-> bar (); B:: bar ();?> 

Output: Salida:

$this is defined (a) de dólares este se define (a)
$this is not defined. $ este no está definido.
$this is defined (b) de dólares este se define (b)
$this is not defined. $ este no está definido.