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

Asked

Viewed 652 times

1

How could I use the method define_title() the variable $extension that is within the method 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";
        }
    }
}

1 answer

5

You are using OOP remember which options best fit when you’re 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";
        }
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.