牛牛在线工具

Table::getName()

收录 8868 个 PHP 函数,含用途说明与用法示例。

Table::getName()

返回 Table 对象的名称

函数名称:Table::getName() 适用版本:PHP 5.3.0 及以上版本 函数描述:Table::getName() 函数用于返回 Table 对象的名称。 用法示例: <?php class Table { private $name; public function __construct($name) { $this->name = $name; } public function getName() { return $this->name; } } $table = new Table("users"); echo $table->getName(); // 输出: users ?> 解释说明: 首先,我们定义了一个名为 Table 的类,它具有一个私有属性 $name 和一个公有方法 getName()。 在类的构造函数中,我们接收一个参数 $name,并将其赋值给 $this->name。 getName() 方法用于返回 $name 属性的值。 在示例中,我们创建了一个名为 $table 的 Table 对象,并传入参数 "users"。 然后,我们调用 $table->getName() 方法来获取对象的名称,并使用 echo 输出结果。