0

I have a class:

namespace Navi\View;

use Navi\Navi;

class View extends Base{
    public function render(){
        $test = 'This is a local variable!';
        $obj = new Navi; //Working, ofcourse!
        include 'file.php';
    }
}

And in "file.php";

<?php
echo $test;
var_dump(new Navi); //Class Navi not found

Why the local $test variable pass to file.php, but Navi class isn't?

Ofcourse, if I use "use Navi\Navi" in "file.php" then code working. I don't understand why!

Any way to using Navi class that not using "use Navi\Navi"?

Please help me!

Thankyou!

1 Answer 1

1

Importing rules are per file basis, meaning included files will NOT inherit the parent file's importing rules.

I've go to change your code in file.php this way:

var_dump(new \Navi\Navi)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.