SlideShare a Scribd company logo
PHP 7.0's
error messages
Having fun with errors
Washington DC, USA, 2015
Agenda
• 2200 error messages to review
• New features, new traps, new messages
Speaker
• Damien Seguy
• CTO at exakat
• PHP static auditing engine
Evolution of error messages
Searching for messages
• PHP-src repository
• zend_error
• zend_throw
• zend_throw_exception
• zend_error_throw
TOP 5 (from the source)
1. Using $this when not in object context (192)
2. Cannot use string offset as an array (74)
3. Cannot use string offset as an object (56)
4. Only variable references should be yielded by
reference (52)
5. Undefined variable: %s (43)
TOP 5 (Google)
1. Call to undefined function
2. Class not found
3. Allowed memory size of
4. Undefined index
5. Undefined variable
Exceptions are on the rise
%
%
%
%
Agenda
• New error messages
• Better linting
• Removed messages
• Cryptic messages
New features
Return value of %s%s%s()
must %s%s, %s%s returned
<?php   
  function x(): myClass {  
   return false;  
} 
   
?>
Uncaught TypeError: Return value of x() must be of the type myClass,
boolean returned in…
Return value of %s%s%s()
must %s%s, %s%s returned
<?php   
  function x(): array {  
   return ;  
  } 
   
?>
Uncaught TypeError: Return value of x() must be of the type array,
none returned in…
Argument %d passed to %s%s%s() must %s
%s, %s%s given, called in %s on line %d
<?php   
function x(array $a)  {  
  return false;  
} 
x(false); 
   
?>
Uncaught TypeError: Argument 1 passed to x() must be of the type
array, boolean given, called in
Default value for parameters with
a float type hint can only be float
<?php   
    function foo(float $a = "3"){  
        return true;  
    }  
?> 
Default value for parameters with
a float type hint can only be float
<?php   
    function foo(float $a =  3 ){  
        return true;  
    }  
?> 
Cannot use temporary
expression in write context
<?php  
$a = 'foo'[0];  
'foo'[0] = 'b';  
?>
Parse error: syntax error, unexpected '=' in
Cannot use temporary
expression in write context
<?php   
$a = 'foo';  
$a[0] = 'b';   
print $a;  
?>
Cannot use "%s" when no
class scope is active
<?php    
  function x(): parent {   
    return new bar();  
 }  
x();  
?>
• self • parent • static
Cannot use "%s" when no
class scope is active
<?php    
class bar extends baz {}   
class foo extends bar {  
  function x(): parent {   
    return new foo();  
 }  
}  
$x = new foo();  $x->x();  
?>
Cannot use "%s" when no
class scope is active
<?php    
class bar extends baz {}   
class foo extends bar {  
  function x(): parent {   
    return new bar();  
 }  
}  
$x = new foo();  $x->x();  
?>
Cannot use "%s" when no
class scope is active
<?php    
class baz {}   
class bar extends baz {}   
class foo extends bar {  
  function x(): parent {   
    return new baz();  
 }  
}  
$x = new foo(); $x->x();  
?>Uncaught TypeError: Return value of foo::x() must be an instance of
bar, instance of baz returned in
Different parents
class great-great-grandparent
class great-grandparent
class parent
class self
class child
class grand-child
class great-grandchild
class great-great-grandchild
<?php 
class self {
  function x() {
    parent::y();
 }
}
<?php 
class self {
  function x() : parent {
    return $something;
 }
}
Cannot use "%s" when no
class scope is active<?php    
class baz {}   
class bar extends baz {}   
class foo extends bar {  
  function x(): grandparent {   
    return new baz();  
 }  
}  
$x = new foo(); $x->x();  
?>
Uncaught TypeError: Return value of foo::x() must be an instance of
grandparent, instance of bar returned
Useful in traits
Fatal error: Cannot access parent:: when current
class scope has no parent
<?php 
trait t {
  function x() : parent {
    return $something;
 }
}
class c {
  use t;
}
cannot declare a return type
• __construct
• __destruct
• __clone
• "PHP 4 constructor"
<?php   
class x {  
    function __construct() : array {  
        return true;  
    }  
    function x() : array {  
        return true;  
    }  
}  
?>
Methods with the same name as their
class will not be constructors in a
future version of PHP; %s has a
deprecated constructor
<?php   
class x {  
    function x() : array {  
        return true;  
    }  
}  
?> M
ost
frequent
error
(95%
)
Invalid UTF-8 codepoint
escape sequence
我爱你
<?php   
$a = "u{6211}u{7231}u{4f60}";  
echo $a;  
?> 
Invalid UTF-8 codepoint
escape sequence
• Incompatible with PHP 5.6
• Good for literals
• Alternatives?
<?php   
$a = "u{de";  
echo $a;  
?> 
<?php  
echo json_decode('"u'.$unicode.'"');  
echo mb_convert_encoding('&#x'.$unicode.';', 'UTF-8', 'HTML-ENTITIES');  
echo html_entity_decode('&#'.hexdec($unicode).';', 0, 'UTF-8');  
     eval('"u{'.$unicode.'}n"');  
?>
New linting
A class constant must not be called 'class';
it is reserved for class name fetching
• Used to be a parse error. Now a nice message.
• Still a bad idea
<?php   
class x {  
    const class = 1;  
    const const = 2;  
}  
?>
A class constant must not be called 'class';
it is reserved for class name fetching
• Outside class will 

generate

the old error
<?php   
//class x {  
    const class = 1;  
//}  
?>
Parse error: syntax error, unexpected 'class' (T_CLASS), expecting
identifier (T_STRING)
Dynamic class names are not
allowed in compile-time ::class fetch
<?php    
$c = new class { 
function f() { 
echo $x::class; 
}
}; 
$c->f(); 
?>
Redefinition of parameter $%s
<?php  
function foo($a, $a, $a) {  
  echo "$an";  
}  
foo(1,2,3);  
?>
Switch statements may only
contain one default clause
<?php   
switch($x) {   
    case '1' :    
        break;   
    default :    
        break;   
    default :    
        break;   
    case '2' :    
        break;   
}   
?>
Switch statements may only
contain one default clause
<?php   
switch($x) {   
    case 1 :    
        break;   
    case 0+1 :    
        break;   
    case '1' :    
        break;   
    case true :    
        break;   
    case 1.0 :    
        break;   
    case $y :    
        break;   
Exceptions must
implement Throwable
<?php    
throw new stdClass();
?> 
Fatal error: Uncaught Error: Cannot throw objects that do not
implement Throwable
Exceptions must
implement Throwable
<?php    
class e implements Throwable {
/* Methods */
 public function  getMessage() {}
 public function  getCode() {}
 public function  getFile() {}
 public function  getLine() {}
 public function  getTrace() {}
 public function  getTraceAsString() {}
 public function  getPrevious() {}
 public function  __toString() {}
}
?> 
Class e cannot implement interface Throwable, extend Exception or
Error instead
Retired messages
Gone for good
	 It is not safe to rely on the system's timezone
settings. You are *required* to use the date.timezone
setting or the date_default_timezone_set() function. In
case you used any of those methods and you are still
getting this warning, you most likely misspelled the
timezone identifier.
Catchable fatal error
<?php  
function x(string $s) {
    echo "$sn";
}
x('php');
?>
Catchable fatal error: Argument 1 passed to x() must be an instance of
string, string given
New scalar typehint
• string, real, bool, float, int
• resource, mixed, numeric, object
• Can't be used for a class name anymore
Catchable fatal error
<?php  
function x(resource $s) {
    echo "$sn";
}
x(fopen('a.php','w+'));
?>
Catchable fatal error: Argument 1 passed to x() must be an instance of
resource, resource given
Fatal Error
<?php 
interface t{} 
trait t{} 
?>
Fatal error: Cannot redeclare class t in
Call-time pass-by-reference
has been removed;
<?php  
$a = 3;  
function f($b) {  
    $b++;  
}  
f(&$a);  
print $a;  
?>
Fatal error: Call-time pass-by-reference has been removed; If you would
like to pass argument by reference, modify the declaration of f(). in
has been removed
Call-time pass-by-reference
has been removed;
<?php  
$a = 3;  
function f($b) {  
    $b++;  
}  
f(&$a);  
print $a;  
?>
PHP Parse error: syntax error, unexpected '&' in
Cryptic messages
Minimum value must be less than
or equal to the maximum value
<?php 
var_dump(random_int(100, 999)); 
var_dump(random_int(-1000, 0)); 
var_dump(random_bytes(10)); 
?>
PHP Parse error: Could not gather sufficient random data
Division of PHP_INT_MIN
by -1 is not an integer
• PHP_INT_MAX : 9223372036854775807
• PHP_INT_MIN is the smallest integer on PHP
• PHP_INT_MIN : -9223372036854775808
• Division or multiplication leads to non-integer
• Uses the Integer Division intdiv()
WebP decode: realloc failed
• New image format for the Web
• Lossless compression, small files
• gdImageCreateFromWebpCtx emit this
• Probably very bad
Function name must be
a string
<?php  
if ($_GET('X') == 'Go') {  
    ProcessFile();  
    return;  
}  
?>
Encoding declaration pragma
must be
the very first statement
in the script
Namespace declaration
statement
has to be
the very first statement
in the script
Namespace declaration
statement
has to be
the very first statement
in the script
Encoding declaration pragma
must be
the very first statement
in the script
<?php 
namespace myNamespace; 
declare(encoding='ISO-8859-1'); 
// code here 
// --enable-zend-multibyte
?>
First STATEMENT EVER
<?php 
declare(encoding='ISO-8859-1'); 
namespace myNamespace;
 
// code here 
// --enable-zend-multibyte
?>
First STATEMENT EVER
<?php
declare(encoding='UTF8'); 
namespace ⼈人 {
echo __NAMESPACE__;
}
?>
You seem to be trying to
use a different language...
<?php  
use strict;
What about my code?
Fun with errors
• Check the errors messages in your application
• die, exit
• echo, print, display, debug, wp_die

(depends on conventions)
• new *Exception()
• What does your application tells you?
• die('I SEE ' . $action . ' - ' . $_POST['categories_id']);
• die("Error: application_top not found.nMake sure you have placed the currency_cron.ph
file in your (renamed) Admin folder.nn");
• die('ERROR: admin/includes/configure.php file not found. Suggest running zc_install/
index.php?');
• die('I WOULD NOT ADD ' . $new_categories_sort_array[$i] . '<br>');
• die('NOTCONFIGURED');
• die('halted');
• die('<pre>' . print_r($inputs, true));
• die('HERE_BE_MONSTERS - could not open file');}
• die('HERE_BE_MONSTERS');}
• die($prod_id);
• die('here');
• die('Sorry. File not found. Please contact the webmaster to report this error.<br />c/
f: ' . $origin_filename);
Thanks
@exakat

More Related Content

PDF
Php 7 errors messages
PDF
Just-In-Time Compiler in PHP 8
PDF
Cli the other SAPI confoo11
PDF
What's new in PHP 8.0?
PDF
Static Optimization of PHP bytecode (PHPSC 2017)
PDF
CLI, the other SAPI phpnw11
PDF
Cli the other sapi pbc11
PDF
Nikita Popov "What’s new in PHP 8.0?"
Php 7 errors messages
Just-In-Time Compiler in PHP 8
Cli the other SAPI confoo11
What's new in PHP 8.0?
Static Optimization of PHP bytecode (PHPSC 2017)
CLI, the other SAPI phpnw11
Cli the other sapi pbc11
Nikita Popov "What’s new in PHP 8.0?"

What's hot (20)

PDF
PHP 7 – What changed internally? (PHP Barcelona 2015)
PDF
PHP 良好實踐 (Best Practice)
PDF
SPL: The Missing Link in Development
PDF
PHP Conference Asia 2016
PPTX
PHP Basics
PPT
Php i basic chapter 3
PPT
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
PPT
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
PDF
PHP Enums - PHPCon Japan 2021
PDF
Typed Properties and more: What's coming in PHP 7.4?
PPT
Basic PHP
PPTX
New in php 7
KEY
SPL, not a bridge too far
PDF
Preparing for the next PHP version (5.6)
PPT
Introduction to php
PDF
PHP 8.1 - What's new and changed
PPTX
A Functional Guide to Cat Herding with PHP Generators
PDF
Data Types In PHP
KEY
Workshop unittesting
PDF
Overview changes in PHP 5.4
PHP 7 – What changed internally? (PHP Barcelona 2015)
PHP 良好實踐 (Best Practice)
SPL: The Missing Link in Development
PHP Conference Asia 2016
PHP Basics
Php i basic chapter 3
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
PHP Enums - PHPCon Japan 2021
Typed Properties and more: What's coming in PHP 7.4?
Basic PHP
New in php 7
SPL, not a bridge too far
Preparing for the next PHP version (5.6)
Introduction to php
PHP 8.1 - What's new and changed
A Functional Guide to Cat Herding with PHP Generators
Data Types In PHP
Workshop unittesting
Overview changes in PHP 5.4
Ad

Similar to errors in php 7 (20)

PDF
PHP 8: Process & Fixing Insanity
PPT
PHP Fuctions.ppt,IT CONTAINS PHP INCLUDE FUNCTION
PDF
PHP unserialization vulnerabilities: What are we missing?
PDF
関西PHP勉強会 php5.4つまみぐい
PDF
What's new in PHP 8.0?
PDF
Giới thiệu PHP 7
PDF
php AND MYSQL _ppt.pdf
PDF
Php Tutorials for Beginners
PPTX
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
PDF
Zend Certification PHP 5 Sample Questions
PDF
Building Testable PHP Applications
PDF
TAKING PHP SERIOUSLY - Keith Adams
PDF
Object Oriented PHP - PART-2
PPTX
Lecture-10_PHP-OOP.pptx
PDF
PHP 5.4 New Features
PDF
PHP traits, treat or threat?
PDF
Strong typing @ php leeds
KEY
Zendcon 09
PDF
Advanced Python, Part 1
PHP 8: Process & Fixing Insanity
PHP Fuctions.ppt,IT CONTAINS PHP INCLUDE FUNCTION
PHP unserialization vulnerabilities: What are we missing?
関西PHP勉強会 php5.4つまみぐい
What's new in PHP 8.0?
Giới thiệu PHP 7
php AND MYSQL _ppt.pdf
Php Tutorials for Beginners
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
Zend Certification PHP 5 Sample Questions
Building Testable PHP Applications
TAKING PHP SERIOUSLY - Keith Adams
Object Oriented PHP - PART-2
Lecture-10_PHP-OOP.pptx
PHP 5.4 New Features
PHP traits, treat or threat?
Strong typing @ php leeds
Zendcon 09
Advanced Python, Part 1
Ad

More from Damien Seguy (20)

PPTX
Strong typing : adoption, adaptation and organisation
PDF
Qui a laissé son mot de passe dans le code
PDF
Analyse statique et applications
PDF
Top 10 pieges php afup limoges
PDF
Top 10 php classic traps DPC 2020
PDF
Meilleur du typage fort (AFUP Day, 2020)
PDF
Top 10 php classic traps confoo
PDF
Tout pour se préparer à PHP 7.4
PDF
Top 10 php classic traps php serbia
PDF
Top 10 php classic traps
PDF
Top 10 chausse trappes
PDF
Code review workshop
PDF
Understanding static analysis php amsterdam 2018
PDF
Review unknown code with static analysis php ce 2018
PDF
Everything new with PHP 7.3
PDF
Php 7.3 et ses RFC (AFUP Toulouse)
PDF
Tout sur PHP 7.3 et ses RFC
PDF
Review unknown code with static analysis php ipc 2018
PDF
Code review for busy people
PDF
Static analysis saved my code tonight
Strong typing : adoption, adaptation and organisation
Qui a laissé son mot de passe dans le code
Analyse statique et applications
Top 10 pieges php afup limoges
Top 10 php classic traps DPC 2020
Meilleur du typage fort (AFUP Day, 2020)
Top 10 php classic traps confoo
Tout pour se préparer à PHP 7.4
Top 10 php classic traps php serbia
Top 10 php classic traps
Top 10 chausse trappes
Code review workshop
Understanding static analysis php amsterdam 2018
Review unknown code with static analysis php ce 2018
Everything new with PHP 7.3
Php 7.3 et ses RFC (AFUP Toulouse)
Tout sur PHP 7.3 et ses RFC
Review unknown code with static analysis php ipc 2018
Code review for busy people
Static analysis saved my code tonight

Recently uploaded (20)

PPTX
Machine Learning_overview_presentation.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Getting Started with Data Integration: FME Form 101
PDF
Machine learning based COVID-19 study performance prediction
PDF
Network Security Unit 5.pdf for BCA BBA.
PPT
Teaching material agriculture food technology
PDF
Encapsulation theory and applications.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
Machine Learning_overview_presentation.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
SOPHOS-XG Firewall Administrator PPT.pptx
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Per capita expenditure prediction using model stacking based on satellite ima...
Unlocking AI with Model Context Protocol (MCP)
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Spectroscopy.pptx food analysis technology
Getting Started with Data Integration: FME Form 101
Machine learning based COVID-19 study performance prediction
Network Security Unit 5.pdf for BCA BBA.
Teaching material agriculture food technology
Encapsulation theory and applications.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
20250228 LYD VKU AI Blended-Learning.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf

errors in php 7

  • 1. PHP 7.0's error messages Having fun with errors Washington DC, USA, 2015
  • 2. Agenda • 2200 error messages to review • New features, new traps, new messages
  • 3. Speaker • Damien Seguy • CTO at exakat • PHP static auditing engine
  • 5. Searching for messages • PHP-src repository • zend_error • zend_throw • zend_throw_exception • zend_error_throw
  • 6. TOP 5 (from the source) 1. Using $this when not in object context (192) 2. Cannot use string offset as an array (74) 3. Cannot use string offset as an object (56) 4. Only variable references should be yielded by reference (52) 5. Undefined variable: %s (43)
  • 7. TOP 5 (Google) 1. Call to undefined function 2. Class not found 3. Allowed memory size of 4. Undefined index 5. Undefined variable
  • 8. Exceptions are on the rise % % % %
  • 9. Agenda • New error messages • Better linting • Removed messages • Cryptic messages
  • 11. Return value of %s%s%s() must %s%s, %s%s returned <?php      function x(): myClass {      return false;   }      ?> Uncaught TypeError: Return value of x() must be of the type myClass, boolean returned in…
  • 12. Return value of %s%s%s() must %s%s, %s%s returned <?php      function x(): array {      return ;     }      ?> Uncaught TypeError: Return value of x() must be of the type array, none returned in…
  • 13. Argument %d passed to %s%s%s() must %s %s, %s%s given, called in %s on line %d <?php    function x(array $a)  {     return false;   }  x(false);      ?> Uncaught TypeError: Argument 1 passed to x() must be of the type array, boolean given, called in
  • 14. Default value for parameters with a float type hint can only be float <?php        function foo(float $a = "3"){           return true;       }   ?> 
  • 15. Default value for parameters with a float type hint can only be float <?php        function foo(float $a =  3 ){           return true;       }   ?> 
  • 16. Cannot use temporary expression in write context <?php   $a = 'foo'[0];   'foo'[0] = 'b';   ?> Parse error: syntax error, unexpected '=' in
  • 17. Cannot use temporary expression in write context <?php    $a = 'foo';   $a[0] = 'b';    print $a;   ?>
  • 18. Cannot use "%s" when no class scope is active <?php       function x(): parent {        return new bar();    }   x();   ?> • self • parent • static
  • 19. Cannot use "%s" when no class scope is active <?php     class bar extends baz {}    class foo extends bar {     function x(): parent {        return new foo();    }   }   $x = new foo();  $x->x();   ?>
  • 20. Cannot use "%s" when no class scope is active <?php     class bar extends baz {}    class foo extends bar {     function x(): parent {        return new bar();    }   }   $x = new foo();  $x->x();   ?>
  • 21. Cannot use "%s" when no class scope is active <?php     class baz {}    class bar extends baz {}    class foo extends bar {     function x(): parent {        return new baz();    }   }   $x = new foo(); $x->x();   ?>Uncaught TypeError: Return value of foo::x() must be an instance of bar, instance of baz returned in
  • 22. Different parents class great-great-grandparent class great-grandparent class parent class self class child class grand-child class great-grandchild class great-great-grandchild <?php  class self {   function x() {     parent::y();  } } <?php  class self {   function x() : parent {     return $something;  } }
  • 23. Cannot use "%s" when no class scope is active<?php     class baz {}    class bar extends baz {}    class foo extends bar {     function x(): grandparent {        return new baz();    }   }   $x = new foo(); $x->x();   ?> Uncaught TypeError: Return value of foo::x() must be an instance of grandparent, instance of bar returned
  • 24. Useful in traits Fatal error: Cannot access parent:: when current class scope has no parent <?php  trait t {   function x() : parent {     return $something;  } } class c {   use t; }
  • 25. cannot declare a return type • __construct • __destruct • __clone • "PHP 4 constructor" <?php    class x {       function __construct() : array {           return true;       }       function x() : array {           return true;       }   }   ?>
  • 26. Methods with the same name as their class will not be constructors in a future version of PHP; %s has a deprecated constructor <?php    class x {       function x() : array {           return true;       }   }   ?> M ost frequent error (95% )
  • 27. Invalid UTF-8 codepoint escape sequence 我爱你 <?php    $a = "u{6211}u{7231}u{4f60}";   echo $a;   ?> 
  • 28. Invalid UTF-8 codepoint escape sequence • Incompatible with PHP 5.6 • Good for literals • Alternatives? <?php    $a = "u{de";   echo $a;   ?>  <?php   echo json_decode('"u'.$unicode.'"');   echo mb_convert_encoding('&#x'.$unicode.';', 'UTF-8', 'HTML-ENTITIES');   echo html_entity_decode('&#'.hexdec($unicode).';', 0, 'UTF-8');        eval('"u{'.$unicode.'}n"');   ?>
  • 30. A class constant must not be called 'class'; it is reserved for class name fetching • Used to be a parse error. Now a nice message. • Still a bad idea <?php    class x {       const class = 1;       const const = 2;   }   ?>
  • 31. A class constant must not be called 'class'; it is reserved for class name fetching • Outside class will 
 generate
 the old error <?php    //class x {       const class = 1;   //}   ?> Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING)
  • 32. Dynamic class names are not allowed in compile-time ::class fetch <?php     $c = new class {  function f() {  echo $x::class;  } };  $c->f();  ?>
  • 33. Redefinition of parameter $%s <?php   function foo($a, $a, $a) {     echo "$an";   }   foo(1,2,3);   ?>
  • 34. Switch statements may only contain one default clause <?php    switch($x) {        case '1' :             break;        default :             break;        default :             break;        case '2' :             break;    }    ?>
  • 35. Switch statements may only contain one default clause <?php    switch($x) {        case 1 :             break;        case 0+1 :             break;        case '1' :             break;        case true :             break;        case 1.0 :             break;        case $y :             break;   
  • 36. Exceptions must implement Throwable <?php     throw new stdClass(); ?>  Fatal error: Uncaught Error: Cannot throw objects that do not implement Throwable
  • 39. Gone for good It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.
  • 40. Catchable fatal error <?php   function x(string $s) {     echo "$sn"; } x('php'); ?> Catchable fatal error: Argument 1 passed to x() must be an instance of string, string given
  • 41. New scalar typehint • string, real, bool, float, int • resource, mixed, numeric, object • Can't be used for a class name anymore
  • 42. Catchable fatal error <?php   function x(resource $s) {     echo "$sn"; } x(fopen('a.php','w+')); ?> Catchable fatal error: Argument 1 passed to x() must be an instance of resource, resource given
  • 44. Call-time pass-by-reference has been removed; <?php   $a = 3;   function f($b) {       $b++;   }   f(&$a);   print $a;   ?> Fatal error: Call-time pass-by-reference has been removed; If you would like to pass argument by reference, modify the declaration of f(). in has been removed
  • 45. Call-time pass-by-reference has been removed; <?php   $a = 3;   function f($b) {       $b++;   }   f(&$a);   print $a;   ?> PHP Parse error: syntax error, unexpected '&' in
  • 47. Minimum value must be less than or equal to the maximum value <?php  var_dump(random_int(100, 999));  var_dump(random_int(-1000, 0));  var_dump(random_bytes(10));  ?> PHP Parse error: Could not gather sufficient random data
  • 48. Division of PHP_INT_MIN by -1 is not an integer • PHP_INT_MAX : 9223372036854775807 • PHP_INT_MIN is the smallest integer on PHP • PHP_INT_MIN : -9223372036854775808 • Division or multiplication leads to non-integer • Uses the Integer Division intdiv()
  • 49. WebP decode: realloc failed • New image format for the Web • Lossless compression, small files • gdImageCreateFromWebpCtx emit this • Probably very bad
  • 50. Function name must be a string <?php   if ($_GET('X') == 'Go') {       ProcessFile();       return;   }   ?>
  • 51. Encoding declaration pragma must be the very first statement in the script
  • 52. Namespace declaration statement has to be the very first statement in the script
  • 53. Namespace declaration statement has to be the very first statement in the script Encoding declaration pragma must be the very first statement in the script
  • 56. You seem to be trying to use a different language... <?php   use strict;
  • 57. What about my code?
  • 58. Fun with errors • Check the errors messages in your application • die, exit • echo, print, display, debug, wp_die
 (depends on conventions) • new *Exception() • What does your application tells you?
  • 59. • die('I SEE ' . $action . ' - ' . $_POST['categories_id']); • die("Error: application_top not found.nMake sure you have placed the currency_cron.ph file in your (renamed) Admin folder.nn"); • die('ERROR: admin/includes/configure.php file not found. Suggest running zc_install/ index.php?'); • die('I WOULD NOT ADD ' . $new_categories_sort_array[$i] . '<br>'); • die('NOTCONFIGURED'); • die('halted'); • die('<pre>' . print_r($inputs, true)); • die('HERE_BE_MONSTERS - could not open file');} • die('HERE_BE_MONSTERS');} • die($prod_id); • die('here'); • die('Sorry. File not found. Please contact the webmaster to report this error.<br />c/ f: ' . $origin_filename);