Php/php7
提供: 初心者エンジニアの簡易メモ
php7はスカラー型を指定できる
public function modUser(array $user): array
{
return $user;
}
型一覧
スカラー
- bool
- int
- float
- double
- string
オブジェクト
- array
- object
- callable
- resource
- null
null許容
function sum(int $a, int $b): ?int
{
return $a + $b;
}
継承クラスの親子でデフォルト設定も厳格に
エラー詳細
Warning: Declaration of ChildDao::findAllByMatchName($name, $flag) should be compatible with ParentDao::findAllByMatchName($name, $flag = NULL)
ChildDao::findAllByMatchName($name, $flag) ParentDao::findAllByMatchName($name, $flag = NULL)
の2つを一致させる必要がある。
ちなみに、PHP8.1から 型不一致でFatalになる。
smartyのassign警告
警告詳細
Warning: Use of undefined constant sures - assumed 'sures' (this will throw an Error in a future version of PHP) in
修正前
$smarty->assign(sures, $sures);
修正後
$smarty->assign('sures', $sures);
