function func() {
}
if (function_exists('func')){
echo 'exists';
}
class MyClass{
}
// 使用前检查类是否存在
if (class_exists('MyClass')) {
$myclass = new MyClass();
}
$filename = 'test.txt';
if (!file_exists($filename)) {
echo $filename . ' not exists.';
}
function name() {
echo 'jobs';
}
$func = 'name';
$func(); //调用可变函数
class book {
function getName() {
return 'bookname';
}
}
$func = 'getName';
$book = new book();
$book->$func();
$func = 'getSpeed'; $className = 'Car'; echo $className::$func(); //动态调用静态方法
class Car {
private static $speed = 10;
public static function getSpeed() {
return self::$speed;
}
public static function speedUp() {
return self::$speed+=10;
}
}
class BigCar extends Car {
public static function start() {
parent::speedUp();
}
}
BigCar::start();
echo BigCar::getSpeed();
class Car {
}
$a = new Car();
$b = new Car();
if ($a == $b) echo '=='; //true
if ($a === $b) echo '==='; //false
class Car {
public $name = 'car';
public function __clone() {
$obj = new Car();
$obj->name = $this->name;
}
}
$a = new Car();
$a->name = 'new car';
$b = clone $a;
var_dump($b);
class Car {
public $name = 'car';
}
$a = new Car();
$str = serialize($a); //对象序列化成字符串
echo $str.'<br>';
$b = unserialize($str); //反序列化为对象
var_dump($b);
$str = 'hello'; $len = strlen($str); echo $len;//输出结果是5
$str = "我爱你"; echo mb_strlen($str,"UTF8");//结果:3,此处的UTF8表示中文编码是UTF8格式,中文一般采用UTF8编码
$str = '99.9';
$result = sprintf('.2f', $str);
echo $result;//结果显示99.90
$str = "what's your name?"; echo addslashes($str);//输出:what\'s your name?
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有