Doc #73717 [Ver]: return-types with NULL not handeled properly

From: Date: Mon, 12 Dec 2016 10:33:05 +0000
Subject: Doc #73717 [Ver]: return-types with NULL not handeled properly
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-14217@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73717&edit=1 ID: 73717 User updated by: spam2 at rhsoft dot net Reported by: spam2 at rhsoft dot net Summary: return-types with NULL not handeled properly Status: Verified Type: Documentation Problem Package: Scripting Engine problem PHP Version: 7.0.14 Block user comment: N Private report: N New Comment: well, and both, not allow NULL in return types as well as for params makes the whole typing for int practically unuseable - the same way as float allows int because it's a subset in non-strict-mode NULL should be casted to 0 (int) or false (bool) because otherwise you have to still use (int)$foo and (bool)$foo in your whole code and instead save overhead because the implicit casting you add overhead by the enforced casting of return values in userland code Previous Comments: ------------------------------------------------------------------------ [2016-12-11 23:52:12] cmb@php.net The "Return Type Declarations" RFC explains the reasoning in the section "Disallowing NULL on Return Types"[1]. Apparantly, this info is missing in the manual proper. [1] https://wiki.php.net/rfc/return_types#disallowing_null_on_return_types ------------------------------------------------------------------------ [2016-12-11 21:07:26] spam2 at rhsoft dot net Description: ------------ Fatal error: Uncaught TypeError: Return value of cl_forum::thread_last_timestamp() must be of the type integer, null returned in /mnt/data/www/thelounge.net/contentlounge/cms/modules/forum/api_forum.php:487 why in the world do i need return (int) here in no-strict-types mode the whole purpose of the return type would be to save the manual casting Test script: --------------- public function thread_last_timestamp(int $thread_id=0): int { switch($thread_id) { case 0: return $this->db->fetch_row($this->db->query('select' . SQL_SMALL_CACHE . 'max(fo_post_timestamp) from ' . sql_prefix . 'forum_posts;', 1, 0))[0]; default: return $this->db->fetch_row($this->db->query('select' . SQL_SMALL_CACHE . 'max(fo_post_timestamp) from ' . sql_prefix . 'forum_posts where fo_post_tid=' . $thread_id . ';', 1, 0))[0]; } } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73717&edit=1

« previous php.doc.bugs (#14217) next »