Fatal error: Uncaught Error: Class "Page" not found in /var/www/html/PHP-and-MySQL-Web-Development/Chapter06/understanding-the-global-namespace-pag-197/index.php:4 Stack trace: #0 {main} thrown in /var/www/html/PHP-and-MySQL-Web-Development/Chapter06/understanding-the-global-namespace-pag-197/index.php on line 4
the problem is in this line $services = new \Page();
if do like this $services = new page\Page(); is working well
index.php
<?php
include "html.php";
use bob\html\page;
$table = new \Page();
$table->title = "My table";
$table->numRows = 5;
?>
<html>
<body>
<?php $table->message(); ?>
</body>
</html>
html.php
<?php
namespace bob\html\page;
class Page {
public $title = "";
public $numRows = 0;
public function message() {
echo "<p>Table '{$this->title}' has {$this->numRows} rows.</p>";
}
}
?>
in the example of the book there is only this line
$services = new \Page();
any code that is not in a declared namespace is considered to be in the global namespace.
think of this as the root directory in our analoguos filesytem.
Imagine we are somewhere in hte bob\html\page namespace, and there just happens to be a globally declared Page class. If you wanted to access this, you could do so by using the backslash in front of the class name, like this
$services = new \Page();