facebook twitter hatena line email

「Php/php7」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「==php7は型を指定できる== public function modUser(array $user): array { return $user; } ==型一覧== *boolean *integer *float *double *string *array *ob...」)
 
(継承クラスの親子でデフォルト設定も厳格に)
 
(同じ利用者による、間の6版が非表示)
行1: 行1:
==php7は型を指定できる==
+
==php7はスカラー型を指定できる==
 
  public function modUser(array $user): array
 
  public function modUser(array $user): array
 
  {
 
  {
行6: 行6:
  
 
==型一覧==
 
==型一覧==
*boolean
+
スカラー
*integer
+
*bool
 +
*int
 
*float
 
*float
 
*double
 
*double
 
*string
 
*string
 +
 +
オブジェクト
 
*array
 
*array
 
*object
 
*object
行22: 行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);