Re: Raise E_NOTICE for null castings

From: Date: Fri, 27 Oct 2017 10:54:49 +0000
Subject: Re: Raise E_NOTICE for null castings
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-100959@lists.php.net to get a copy of this message
> > Hi, I would like to propose an RFC to raise an E_NOTICE when a variable >> "initialized" to null is casted to other types: >> >> $foo = null; >> var_dump($foo['bar']); >> var_dump($foo . 'bar'); >> var_dump($foo + 2); >> var_dump($foo & 2); >> // At the time being, this code produces no errors >> >> The eventual vote may be split one for each case. >> >> What do you think? >> > > pleae don't break code like this which is a useful case for access > directly a array field returned from a function and so makes this to a > one-liner without check the result > > public function GetMaxSort(): int > { > return (int)mysqli_fetch_row($this->cl_api->db->query("select > SQL_NO_CACHE max(hsort) from {$this->cl_api->sql_prefix}main", 1))[0]; > > } > Just use return (int) mysqli_fetch_row($this->cl_api->db->query("select SQL_NO_CACHE max(hsort) from {$this->cl_api->sql_prefix}main", 1))[0] ?? 0; Regards, Niklas

« previous php.internals (#100959) next »