| Author |  | 
| spser 
 
 
 Joined: 29 Aug 2016
 Posts: 97
 
 
 | 
|  Posted: Mon 07 Dec '20 6:34    Post subject: PHP8  Too many warnings, how to distinguish |   |  
| 
 |  
| Countless _GET['**'] _POST['**'] calls, warnings pop up. Now you need to close the warning report to run, but some warning reports are indispensable. 
 How should I be compatible?
 
 
 "A number of notices have been converted into warnings:
 
 Attempting to read an undefined variable.
 Attempting to read an undefined property.
 Attempting to read an undefined array key.
 Attempting to read a property of a non-object.
 Attempting to access an array index of a non-array.
 Attempting to convert an array to string.
 Attempting to use a resource as an array key.
 Attempting to use null, a boolean, or a float as a string offset.
 Attempting to read an out-of-bounds string offset.
 Attempting to assign an empty string to a string offset.
 Attempting to assign multiple bytes to a string offset will now emit a warning."
 |  | 
| Back to top |  | 
| James Blond Moderator
 
  
 Joined: 19 Jan 2006
 Posts: 7442
 Location: EU, Germany, Next to Hamburg
 
 | 
|  Posted: Mon 07 Dec '20 15:47    Post subject: |   |  
| 
 |  
| The true way would be to check of that variable index is available. 
 e.g.
 
  	  | Code: |  	  | if (isset($_POST['x']) {
 //...
 }
 
 | 
 
 Thad bad and ugly way is to change the error level in php.ini, since it is now E_ALL by default. PHP 7.x it was E_ALL & ~E_NOTICE
 |  | 
| Back to top |  | 
| spser 
 
 
 Joined: 29 Aug 2016
 Posts: 97
 
 
 | 
|  Posted: Fri 11 Dec '20 10:38    Post subject: |   |  
| 
 |  
| Too many places are written as if(POST[xx]), it is very difficult to change. Also don't want to turn off the warning prompt...
 |  | 
| Back to top |  | 
| James Blond Moderator
 
  
 Joined: 19 Jan 2006
 Posts: 7442
 Location: EU, Germany, Next to Hamburg
 
 | 
|  Posted: Fri 11 Dec '20 15:06    Post subject: |   |  
| 
 |  
|  	  | Quote: |  	  | Also don't want to turn off the warning prompt... | 
 
 What are you talking about?
 |  | 
| Back to top |  | 
| spser 
 
 
 Joined: 29 Aug 2016
 Posts: 97
 
 
 | 
|  Posted: Thu 24 Dec '20 8:44    Post subject: |   |  
| 
 |  
|  	  | James Blond wrote: |  	  |  	  | Quote: |  	  | Also don't want to turn off the warning prompt... | 
 
 What are you talking about?
 | 
 
 
  	  | Code: |  	  | php 5 / php 7
 echo $arr['user'][$userid][$this->age];  // return null
 
 php 8
 echo $arr['user'][$userid][$this->age];  // Warning: Undefined variable ***
 // How to write so as not to make mistakes??
 if( isset($arr) && isset($arr['user']) && isset($userid) && isset($this->age) && isset($arr['user'][$userid])..... )
 
 Unrestricted isset?
 
 | 
 |  | 
| Back to top |  | 
| James Blond Moderator
 
  
 Joined: 19 Jan 2006
 Posts: 7442
 Location: EU, Germany, Next to Hamburg
 
 | 
|  Posted: Mon 28 Dec '20 23:43    Post subject: |   |  
| 
 |  
|  	  | spser wrote: |  	  | 
 
  	  | Code: |  	  | php 5 / php 7
 echo $arr['user'][$userid][$this->age];  // return null
 
 php 8
 echo $arr['user'][$userid][$this->age];  // Warning: Undefined variable ***
 // How to write so as not to make mistakes??
 if( isset($arr) && isset($arr['user']) && isset($userid) && isset($this->age) && isset($arr['user'][$userid])..... )
 
 Unrestricted isset?
 
 | 
 | 
 
 For the Pointer you can the PHP 8 new feature https://wiki.php.net/rfc/nullsafe_operator
 I don't know if that works for array, too. PHP 8 is fairly new.
 |  | 
| Back to top |  | 
| spser 
 
 
 Joined: 29 Aug 2016
 Posts: 97
 
 
 | 
|  Posted: Tue 05 Jan '21 7:49    Post subject: |   |  
| 
 |  
|  	  | James Blond wrote: |  	  |  	  | spser wrote: |  	  | 
 
  	  | Code: |  	  | php 5 / php 7
 echo $arr['user'][$userid][$this->age];  // return null
 
 php 8
 echo $arr['user'][$userid][$this->age];  // Warning: Undefined variable ***
 // How to write so as not to make mistakes??
 if( isset($arr) && isset($arr['user']) && isset($userid) && isset($this->age) && isset($arr['user'][$userid])..... )
 
 Unrestricted isset?
 
 | 
 | 
 
 For the Pointer you can the PHP 8 new feature https://wiki.php.net/rfc/nullsafe_operator
 I don't know if that works for array, too. PHP 8 is fairly new.
 | 
 
 
  	  | Code: |  	  | $arr = array(); 
 echo $arr['bb']?['dd'];  // Parse error: syntax error, unexpected token ";"
 echo $arr['bb'?]['dd'];    // Parse error: syntax error, unexpected token "]"
 
 | 
 don't works....  help.
 |  | 
| Back to top |  | 
| James Blond Moderator
 
  
 Joined: 19 Jan 2006
 Posts: 7442
 Location: EU, Germany, Next to Hamburg
 
 | 
|  Posted: Tue 05 Jan '21 16:28    Post subject: |   |  
| 
 |  
| Well then you have to use the isset function |  | 
| Back to top |  | 
| spser 
 
 
 Joined: 29 Aug 2016
 Posts: 97
 
 
 | 
|  Posted: Wed 06 Jan '21 8:39    Post subject: |   |  
| 
 |  
|  	  | James Blond wrote: |  	  | Well then you have to use the isset function | 
 
 Isset has to be used many, many times, and even the judgment is incomplete.
 
 Not the best way.
 |  | 
| Back to top |  | 
| James Blond Moderator
 
  
 Joined: 19 Jan 2006
 Posts: 7442
 Location: EU, Germany, Next to Hamburg
 
 | 
|  Posted: Wed 06 Jan '21 9:42    Post subject: |   |  
| 
 |  
| it seems your code is not PHP 8 ready. 
 You could change the error level in php.ini to
 
 
 
 That doesn't improve the code, but it will hide the notice errors.
 |  | 
| Back to top |  | 
| spser 
 
 
 Joined: 29 Aug 2016
 Posts: 97
 
 
 | 
|  Posted: Thu 07 Jan '21 8:44    Post subject: |   |  
| 
 |  
|  	  | James Blond wrote: |  	  | it seems your code is not PHP 8 ready. 
 You could change the error level in php.ini to
 
 
 
 That doesn't improve the code, but it will hide the notice errors.
 | 
 
 php8 returns a warning, not a prompt E_NOTICE
 |  | 
| Back to top |  | 
| James Blond Moderator
 
  
 Joined: 19 Jan 2006
 Posts: 7442
 Location: EU, Germany, Next to Hamburg
 
 | 
|  Posted: Thu 07 Jan '21 9:35    Post subject: |   |  
| 
 |  
|  	  | spser wrote: |  	  | 
 php8 returns a warning, not a prompt E_NOTICE
 | 
 
 RTFM? [1] Sure you can turn of Warnings, too. However, I don't recommend running your code with PHP 8. Is there a specific reason you need PHP 8?
 
 
 
 [1] https://www.php.net/manual/en/function.error-reporting
 |  | 
| Back to top |  | 
| spser 
 
 
 Joined: 29 Aug 2016
 Posts: 97
 
 
 | 
|  Posted: Fri 08 Jan '21 10:09    Post subject: |   |  
| 
 |  
|  	  | James Blond wrote: |  	  |  	  | spser wrote: |  	  | 
 php8 returns a warning, not a prompt E_NOTICE
 | 
 
 RTFM? [1] Sure you can turn of Warnings, too. However, I don't recommend running your code with PHP 8. Is there a specific reason you need PHP 8?
 
 
 
 [1] https://www.php.net/manual/en/function.error-reporting
 | 
 
 Early technical test, operation and maintenance may upgrade php8
 |  | 
| Back to top |  |