Using namespace in included script

by godzillante   Last Updated January 11, 2019 11:26 AM

I'm using a namespace in a PHP script, which in turn includes other scripts. For example:

main.php:

use Illuminate\Database\Capsule\Manager as Capsule;

$page_name = "something";

require_once('views/' . $page_name . '.php');

views/something.php:

...
$my_res = Capsule::table('my_table')->get();
...

Results

exception '...\ErrorException' with message 'Class 'Capsule' not found' in /my/path/views/autoreboot.php:10

Maybe it's just me being silly, but I can't get to understand this behaviour. Am I forced to use use within any script? Can someone explain?



Related Questions


Updated July 18, 2018 06:26 AM

Updated September 24, 2017 03:26 AM

Updated October 07, 2017 00:26 AM

Updated February 04, 2017 14:11 PM

Updated April 23, 2017 02:26 AM