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


Smartphone icons created by Freepik - Flaticon

PHP Namespaces

Using Namespaces

Table 'My table' has 5 rows.

The row has 3 cells.

// code from the beginning of the file
<?php
namespace Html;
include "include/scripts/php/Html.php";

$table = new Table();
$table->title = "My table";
$table->numRows = 5;

$row = new Row();
$row->numCells = 3;
?>

// code from 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(); ?>
<?php $row->message(); ?>