Ver Mensaje Individual
  #8 (permalink)  
Antiguo 07/02/2012, 16:32
Avatar de andresdzphp
andresdzphp
Colaborador
 
Fecha de Ingreso: julio-2011
Ubicación: $this->Colombia;
Mensajes: 2.749
Antigüedad: 13 años, 7 meses
Puntos: 793
Respuesta: Pasar variables de funciones

Según las necesidades es mejor que los atributos sean privados. También podría ser así:

Código PHP:
Ver original
  1. <?php
  2.  
  3. class Algo
  4. {
  5.     private $_variable;
  6.    
  7.     public function __construct($str)
  8.     {
  9.         $this->_variable = $str;
  10.     }
  11.    
  12.     public function getVariable()
  13.     {
  14.         return $this->_variable;
  15.     }
  16. }
  17.  
  18. $a = new Algo('Hola Mundo');
  19. echo $a->getVariable(); //Hola Mundo
__________________
Si sabemos como leer e interpretar el manual será mucho más fácil aprender PHP. En lugar de confiar en ejemplos o copiar y pegar - PHP