Kata kunci namespace
digunakan untuk menyatakan di mana namespace file PHP beroperasi. Namespaces mencegah konflik antar kelas yang memiliki nama yang sama dan dapat digunakan untuk mengatur kode dengan mengelompokkan kelas terkait.
Contoh
Buat kelas Tabel di namespace Html:
<?php namespace Html; class Table { public $title = ""; public $numRows = 0; public function message() { echo "<p>Table '{$this->title}' has {$this->numRows} rows.</p>"; } } $table = new Table(); $table->title = "Tabelnya"; $table->numRows = 5; ?> <!DOCTYPE html> <html> <body> <?php $table->message(); ?> </body> </html>