Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/11/2011, 23:57
opzina2
 
Fecha de Ingreso: abril-2009
Mensajes: 46
Antigüedad: 15 años, 9 meses
Puntos: 1
Llamar o hacer referencia a una propiedad

Practica: Simple clase para leer archivo de texto linea por linea.

Duda:
¿Cómo puedo llamar a $thiss->line dentro del metodo view();? El objetivo es ver cada linea.

Ej.
Código PHP:
Ver original
  1. public function view() {
  2.         return $this->line;
  3.     }

Código PHP:
<?php
class file {

    private 
$path;
    private 
$file;
    private 
$finalpath;
        private 
$line;
    
    public function 
__construct($ruta$filename) {
        
$this->path $ruta;
        
$this->file $filename;
        
$this->finalpath $this->path "/" $this->file;
    }
    
    
    public function 
read() {
        
        if (
is_dir($this->path) && is_file($this->finalpath)) {
            return 
file($this->finalpath);
        }
        
        return 
false;    
    }
    
    public function 
walk() {
        
        if (
is_array($this->read())) {
            foreach (
$this->read() as $value) {
                
$this->line .= $value;
            }
            return 
$this->line;
        }
    }

    public function 
view() {
        return 
$this->walk();
    }
    
}
?>

Última edición por opzina2; 01/12/2011 a las 00:16