Create a Table class in the Html namespace:
<?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 = "My table";
$table->numRows = 5;
?>
<!DOCTYPE html>
<html>
<body>
<?php
$table->message();
?>
</body>
</html>
Try it Yourself »
The namespace
keyword is used to declare in which namespace a PHP file is operating. Namespaces prevent conflicts between classes that have the same name and can be used to organize code by grouping related classes together.
Read more about namespaces in our PHP Namespaces Tutorial.
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!