Ver Mensaje Individual
  #2 (permalink)  
Antiguo 20/08/2009, 20:28
Avatar de GatorV
GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años, 9 meses
Puntos: 2135
Respuesta: Type casting en PHP 5 (como JAVA o .NET)

De hecho es de la misma forma, pero puedes aprovechar el método mágico __toString(), revisa lo siguiente:

Código PHP:
Ver original
  1. class B
  2. {
  3.     private $_texto;
  4.  
  5.     public function devuelveTexto()
  6.     {
  7.         return $this->_texto;
  8.     }
  9.  
  10.     public function __toString()
  11.    {
  12.         return $this->_texto;
  13.     }
  14. }
  15.  
  16. class A
  17. {
  18.     private $_colB;
  19.  
  20.     public function addB(B $b)
  21.     {
  22.         $this->_colB[] = $b;
  23.     }
  24.  
  25.     public function verificar($textoAVerificar)
  26.     {
  27.         foreach( $this->_colB as $B) {
  28.                if ($B == $textoAVerificar) {
  29.                       $encontrado = true;
  30.                }
  31.         }
  32.     }
  33. }

Saludos.