How to use a variable within another method of the same class?

1

How can I use the define_title () method of the $extension variable inside the file_verify >?

class Title extends Imoveis
{
    public function file_verify($file)
    {
        $file       = explode("/", $file);
        $file       = $file[1];
        $extension  = pathinfo($file);
        $extension  = $extension['extension'];
    }

    public function define_title()
    {
        if(isset($extension) && $extension == 'php')
        {
            return "Bingooooooo";
        }
    }
}
    
asked by anonymous 27.12.2015 / 17:36

1 answer

5

You are using OOP remember which options best fit when you are going to solve scope problems.

class Title extends Imoveis
{
    private $extension;     
    public function file_verify($file)
    {       
        $file       = explode("/", $file);
        $file       = $file[1];
        $extension  = pathinfo($file);
        $this->extension  = $extension['extension'];
    }

    public function define_title()
    {
        if(isset($this->extension) && $this->extension == 'php')
        {
            return "Bingooooooo";
        }
    }
}
    
27.12.2015 / 18:12