[php-src] Issue #9502: Wrong return type for a function returns bool(true)

From: Date: Wed, 07 Sep 2022 23:23:19 +0000
Subject: [php-src] Issue #9502: Wrong return type for a function returns bool(true)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-242375@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/9502 Author: DeveloperLewis ### Description The following code: ```php public static function getArticleViews(int $article_id): bool|array { $sql = "SELECT views FROM articles WHERE article_id = ?"; //Database connection $database = new \classes\Database(); $pdo = $database->getPdo(); //Prepared statements $stmt = $pdo->prepare($sql); $stmt->bindParam(1, $article_id, \PDO::PARAM_INT); if (!$stmt->execute()) { return false; } if (!$result = $stmt->fetchAll()) { return false; } //returns total views for specified article return $result[0]['views']; } $views = classes\models\article\Article::getArticleViews(68); var_dump($views); ``` Resulted in this output: ```php bool(true) ``` But I expected this output instead: ``` int(5) ``` However, if I use the correct return type bool|int, I get the correct output. I have no idea where the bool(true) is coming from, but shouldn't there be some kind of error to state that the return type is not the same type that matches the function? ### PHP Version PHP 8.1.6 ### Operating System Windows 10

« previous php.bugs (#242375) next »