This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

PHP Namespaces

Namespace Alias

In this example "T" is used as a Namespace alias for Html\Table.

Table 'My table' has 5 rows.

// code from the beginning of the file
<?php
include "include/scripts/php/Html.php";
use Html\Table as T;
$table = new T();
$table->title = "My table";
$table->numRows = 5;
?>

// code form the external file
<?php
namespace Html;
class Table {
  public $title = "";
  public $numRows = 0;

  public function message() {
    echo "<p>Table '{$this->title}' has {$this->numRows} rows.</p>";
  }
}

class Row {
  public $numCells = 0;
  public function message() {
    echo "<p>The row has {$this->numCells} cells.</p>";
  }
}
?>

// code from the body of this page
<?php $table->message(); ?>