i have 3 Files, declaring a namespace (minimalistic example):
<?php //f1.php
namespace Sheet;
$base = [1,2,3];
?>
<?php // f2.php
namespace Sheet;
require_once('f1.php');
var_dump($base); // ----> array(1,2,3)
class Reader {
public static function get($pos) {
GLOBAL $base;
var_dump($base); // ----> NULL
foreach ($base as $idx => $val) {
if ($pos == ($idx +1)) return $base[$idx];
}
return null;
}
}
?>
<?php //test.php
namespace Test;
require_once('f2.php');
print \Sheet\Reader::get(1); // expected: '2'
?>
Somehow, i get an invalid argument exception in foreach.
I wonder whats the scope for the GLOBAL declaration is - any ideas?
edit: how can i access that variable within the function get()
in a more convenient way?