


























作为一名专业的PHP开发人员,一定要懂得流行的技术规范,如果连规范都不知道,怎么能保证写出规范的代码呢?
https://learnku.com/docs/psr, 比较重要的规范是PSR-4 自动加载规范
两个都是new对象
php
class Father {
public function getNewFather() {
return new self();
}
public function getNewCaller() {
return new static();
}
}
class Sun1 extends Father {
}
class Sun2 extends Father {
}
$sun1 = new Sun1();
$sun2 = new Sun2();
// Father
print get_class($sun1->getNewFather());
// Sun1
print get_class($sun1->getNewCaller());
// Father
print get_class($sun2->getNewFather());
// Sun2
print get_class($sun2->getNewCaller());get_class()方法是用于获取实例所属的类名。
php
<?php
function sum(...$numbers) {
$acc = 0;
foreach ($numbers as $n) {
$acc += $n;
}
return $acc;
}
echo sum(1, 2, 3, 4);
echo sum(1,2,3,4,5,6)这是Laravel文件系统中删除文件方法的源码 如果删除多个文件,可以传数组或多个参数
php
public function delete($paths)
{
$paths = is_array($paths) ? $paths : func_get_args();
$success = true;
foreach ($paths as $path) {
try {
if (! @unlink($path)) {
$success = false;
}
} catch (ErrorException $e) {
$success = false;
}
}
return $success;
}总结:该函数接受可变数量的参数。参数将作为数组传递给给定变量
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。