basename
定义和用法
basename() 函数返回路径中的文件名部分。
语法
basename(path,suffix)
参数 | 描述 |
---|---|
path | 必需。规定要检查的路径。 |
suffix | 可选。规定文件扩展名。如果文件有 suffix,则不会输出这个扩展名。 |
例子
<?php
$path = "/testweb/home.php";
//显示带有文件扩展名的文件名
echo basename($path);
//显示不带有文件扩展名的文件名
echo basename($path,".php");
?>
输出:
home.php
home
property_exists — 检查对象或类是否具有该属性
说明
bool
property_exists (
mixed $class ,
string $property )
本函数检查给出的 property 是否存在于指定的类中(以及是否能在当前范围内访问)。
Note : As opposed with isset() , property_exists() returns TRUE even if the property has the value NULL .
参数
-
class
-
字符串形式的类名或要检查的类的一个对象
property
-
属性的名字
返回值
如果该属性存在则返回 TRUE ,如果不存在则返回 FALSE ,出错返回 NULL 。
范例
Example#1 property_exists() 例子
<?php
class myClass {
public $mine ;
private $xpto ;
static function test () {
var_dump ( property_exists ( 'myClass' , 'xpto' )); // true, it can be accessed from here
}
}
var_dump ( property_exists ( 'myClass' , 'mine' )); //true
var_dump ( property_exists (new myClass , 'mine' )); //true
var_dump ( property_exists ( 'myClass' , 'xpto' )); //false, isn't public
myClass :: test ();
?>