「Php/php7」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→型一覧) |
(→継承クラスの親子でデフォルト設定も厳格に) |
||
| (同じ利用者による、間の4版が非表示) | |||
| 行7: | 行7: | ||
==型一覧== | ==型一覧== | ||
スカラー | スカラー | ||
| − | * | + | *bool |
*int | *int | ||
*float | *float | ||
| 行25: | 行25: | ||
return $a + $b; | return $a + $b; | ||
} | } | ||
| + | |||
| + | ==継承クラスの親子でデフォルト設定も厳格に== | ||
| + | エラー詳細 | ||
| + | Warning: Declaration of ChildDao::findAllByMatchName($name, $flag) should be compatible with ParentDao::findAllByMatchName($name, $flag = NULL) | ||
| + | |||
| + | <pre> | ||
| + | ChildDao::findAllByMatchName($name, $flag) | ||
| + | ParentDao::findAllByMatchName($name, $flag = NULL) | ||
| + | </pre> | ||
| + | の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); | ||
2026年4月5日 (日) 00:51時点における最新版
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);
