SlideShare ist ein Scribd-Unternehmen logo
1 von 53
Downloaden Sie, um offline zu lesen
PHP 7.0'S
ERROR MESSAGES
HAVING FUN WITH ERRORS
PHPAmersfoort
AGENDA
• 2229 error messages to review
• New gotchas
• New features, new messages
SPEAKER
• Damien Seguy
• CTO at exakat
• "Ik ben een boterham" : I'm a resident
• Automated code audit services
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 (New features)
• Better linting
• Removed messages
• Cryptic messages
NEW FEATURES
RETURN VALUE OF %S%S%S()
MUST %S%S, %S%S RETURNED
<?php   
  function x(): array {  
   return false;  
} 
   
?>
Uncaught TypeError: Return value of x() must be of the type array,
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  
'foo'[0] = 'b';  
?>
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
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
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;  
    }  
}  
?>
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 mb_convert_encoding('&#x'.$unicode.';', 'UTF-8', 'HTML-ENTITIES');  
echo json_decode('"u'.$unicode.'"');  
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 rarely useful
<?php   
class x {  
    const class = 1;  
}  
?>
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 rarely useful
• 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
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 REMOVE
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)); 
?>
DIVISION OF PHP_INT_MIN BY
-1 IS NOT AN INTEGER
• PHP_INT_MIN is the smallest integer on PHP
• PHP_INT_MAX : 9223372036854775807
• 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 
declare(encoding='ISO-8859-1'); 
namespace myNamespace; 
// code here 
// --enable-zend-multibyte
?>
FIRST STATEMENT EVER
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.php 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);
DANK U WEL
@EXAKAT

Weitere ähnliche Inhalte

Was ist angesagt?

Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Fwdays
 
PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)Win Yu
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Developmentjsmith92
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Muhamad Al Imran
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Muhamad Al Imran
 
PHP Conference Asia 2016
PHP Conference Asia 2016PHP Conference Asia 2016
PHP Conference Asia 2016Britta Alex
 
PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021Ayesh Karunaratne
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Nikita Popov
 
Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)Damien Seguy
 
PHP 8.1 - What's new and changed
PHP 8.1 - What's new and changedPHP 8.1 - What's new and changed
PHP 8.1 - What's new and changedAyesh Karunaratne
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsMark Baker
 
Overview changes in PHP 5.4
Overview changes in PHP 5.4Overview changes in PHP 5.4
Overview changes in PHP 5.4Tien Xuan
 

Was ist angesagt? (20)

Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 
PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
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 i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
PHP Conference Asia 2016
PHP Conference Asia 2016PHP Conference Asia 2016
PHP Conference Asia 2016
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021
 
New in php 7
New in php 7New in php 7
New in php 7
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
 
Basic PHP
Basic PHPBasic PHP
Basic PHP
 
Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)
 
SPL, not a bridge too far
SPL, not a bridge too farSPL, not a bridge too far
SPL, not a bridge too far
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
PHP 8.1 - What's new and changed
PHP 8.1 - What's new and changedPHP 8.1 - What's new and changed
PHP 8.1 - What's new and changed
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP Generators
 
Overview changes in PHP 5.4
Overview changes in PHP 5.4Overview changes in PHP 5.4
Overview changes in PHP 5.4
 
Data Types In PHP
Data Types In PHPData Types In PHP
Data Types In PHP
 
Workshop unittesting
Workshop unittestingWorkshop unittesting
Workshop unittesting
 

Ähnlich wie Php 7 errors messages

Quality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormQuality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormMichelangelo van Dam
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
Damien seguy php 5.6
Damien seguy php 5.6Damien seguy php 5.6
Damien seguy php 5.6Damien Seguy
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applicationschartjes
 
Preparing for the next php version
Preparing for the next php versionPreparing for the next php version
Preparing for the next php versionDamien Seguy
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsJagat Kothari
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overviewjsmith92
 
Object Oriented PHP - PART-2
Object Oriented PHP - PART-2Object Oriented PHP - PART-2
Object Oriented PHP - PART-2Jalpesh Vasa
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricksPhpspec tips&amp;tricks
Phpspec tips&amp;tricksFilip Golonka
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin GeneratorJohn Cleveley
 
Giới thiệu PHP 7
Giới thiệu PHP 7Giới thiệu PHP 7
Giới thiệu PHP 7ZendVN
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsMark Baker
 
D7 theming what's new - London
D7 theming what's new - LondonD7 theming what's new - London
D7 theming what's new - LondonMarek Sotak
 
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)Nikita Popov
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress DeveloperJoey Kudish
 

Ähnlich wie Php 7 errors messages (20)

Quality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormQuality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStorm
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Damien seguy php 5.6
Damien seguy php 5.6Damien seguy php 5.6
Damien seguy php 5.6
 
Php
PhpPhp
Php
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Preparing for the next php version
Preparing for the next php versionPreparing for the next php version
Preparing for the next php version
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample Questions
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 
Object Oriented PHP - PART-2
Object Oriented PHP - PART-2Object Oriented PHP - PART-2
Object Oriented PHP - PART-2
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricksPhpspec tips&amp;tricks
Phpspec tips&amp;tricks
 
What's new with PHP7
What's new with PHP7What's new with PHP7
What's new with PHP7
 
Fatc
FatcFatc
Fatc
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin Generator
 
Giới thiệu PHP 7
Giới thiệu PHP 7Giới thiệu PHP 7
Giới thiệu PHP 7
 
99% is not enough
99% is not enough99% is not enough
99% is not enough
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP Generators
 
D7 theming what's new - London
D7 theming what's new - LondonD7 theming what's new - London
D7 theming what's new - London
 
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)
 
PHPSpec BDD Framework
PHPSpec BDD FrameworkPHPSpec BDD Framework
PHPSpec BDD Framework
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress Developer
 

Mehr von Damien Seguy

Strong typing @ php leeds
Strong typing  @ php leedsStrong typing  @ php leeds
Strong typing @ php leedsDamien Seguy
 
Strong typing : adoption, adaptation and organisation
Strong typing : adoption, adaptation and organisationStrong typing : adoption, adaptation and organisation
Strong typing : adoption, adaptation and organisationDamien Seguy
 
Qui a laissé son mot de passe dans le code
Qui a laissé son mot de passe dans le codeQui a laissé son mot de passe dans le code
Qui a laissé son mot de passe dans le codeDamien Seguy
 
Analyse statique et applications
Analyse statique et applicationsAnalyse statique et applications
Analyse statique et applicationsDamien Seguy
 
Top 10 pieges php afup limoges
Top 10 pieges php   afup limogesTop 10 pieges php   afup limoges
Top 10 pieges php afup limogesDamien Seguy
 
Top 10 php classic traps DPC 2020
Top 10 php classic traps DPC 2020Top 10 php classic traps DPC 2020
Top 10 php classic traps DPC 2020Damien Seguy
 
Meilleur du typage fort (AFUP Day, 2020)
Meilleur du typage fort (AFUP Day, 2020)Meilleur du typage fort (AFUP Day, 2020)
Meilleur du typage fort (AFUP Day, 2020)Damien Seguy
 
Top 10 php classic traps confoo
Top 10 php classic traps confooTop 10 php classic traps confoo
Top 10 php classic traps confooDamien Seguy
 
Tout pour se préparer à PHP 7.4
Tout pour se préparer à PHP 7.4Tout pour se préparer à PHP 7.4
Tout pour se préparer à PHP 7.4Damien Seguy
 
Top 10 php classic traps php serbia
Top 10 php classic traps php serbiaTop 10 php classic traps php serbia
Top 10 php classic traps php serbiaDamien Seguy
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic trapsDamien Seguy
 
Top 10 chausse trappes
Top 10 chausse trappesTop 10 chausse trappes
Top 10 chausse trappesDamien Seguy
 
Code review workshop
Code review workshopCode review workshop
Code review workshopDamien Seguy
 
Understanding static analysis php amsterdam 2018
Understanding static analysis   php amsterdam 2018Understanding static analysis   php amsterdam 2018
Understanding static analysis php amsterdam 2018Damien Seguy
 
Review unknown code with static analysis php ce 2018
Review unknown code with static analysis   php ce 2018Review unknown code with static analysis   php ce 2018
Review unknown code with static analysis php ce 2018Damien Seguy
 
Everything new with PHP 7.3
Everything new with PHP 7.3Everything new with PHP 7.3
Everything new with PHP 7.3Damien Seguy
 
Php 7.3 et ses RFC (AFUP Toulouse)
Php 7.3 et ses RFC  (AFUP Toulouse)Php 7.3 et ses RFC  (AFUP Toulouse)
Php 7.3 et ses RFC (AFUP Toulouse)Damien Seguy
 
Tout sur PHP 7.3 et ses RFC
Tout sur PHP 7.3 et ses RFCTout sur PHP 7.3 et ses RFC
Tout sur PHP 7.3 et ses RFCDamien Seguy
 
Review unknown code with static analysis php ipc 2018
Review unknown code with static analysis   php ipc 2018Review unknown code with static analysis   php ipc 2018
Review unknown code with static analysis php ipc 2018Damien Seguy
 
Code review for busy people
Code review for busy peopleCode review for busy people
Code review for busy peopleDamien Seguy
 

Mehr von Damien Seguy (20)

Strong typing @ php leeds
Strong typing  @ php leedsStrong typing  @ php leeds
Strong typing @ php leeds
 
Strong typing : adoption, adaptation and organisation
Strong typing : adoption, adaptation and organisationStrong typing : adoption, adaptation and organisation
Strong typing : adoption, adaptation and organisation
 
Qui a laissé son mot de passe dans le code
Qui a laissé son mot de passe dans le codeQui a laissé son mot de passe dans le code
Qui a laissé son mot de passe dans le code
 
Analyse statique et applications
Analyse statique et applicationsAnalyse statique et applications
Analyse statique et applications
 
Top 10 pieges php afup limoges
Top 10 pieges php   afup limogesTop 10 pieges php   afup limoges
Top 10 pieges php afup limoges
 
Top 10 php classic traps DPC 2020
Top 10 php classic traps DPC 2020Top 10 php classic traps DPC 2020
Top 10 php classic traps DPC 2020
 
Meilleur du typage fort (AFUP Day, 2020)
Meilleur du typage fort (AFUP Day, 2020)Meilleur du typage fort (AFUP Day, 2020)
Meilleur du typage fort (AFUP Day, 2020)
 
Top 10 php classic traps confoo
Top 10 php classic traps confooTop 10 php classic traps confoo
Top 10 php classic traps confoo
 
Tout pour se préparer à PHP 7.4
Tout pour se préparer à PHP 7.4Tout pour se préparer à PHP 7.4
Tout pour se préparer à PHP 7.4
 
Top 10 php classic traps php serbia
Top 10 php classic traps php serbiaTop 10 php classic traps php serbia
Top 10 php classic traps php serbia
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic traps
 
Top 10 chausse trappes
Top 10 chausse trappesTop 10 chausse trappes
Top 10 chausse trappes
 
Code review workshop
Code review workshopCode review workshop
Code review workshop
 
Understanding static analysis php amsterdam 2018
Understanding static analysis   php amsterdam 2018Understanding static analysis   php amsterdam 2018
Understanding static analysis php amsterdam 2018
 
Review unknown code with static analysis php ce 2018
Review unknown code with static analysis   php ce 2018Review unknown code with static analysis   php ce 2018
Review unknown code with static analysis php ce 2018
 
Everything new with PHP 7.3
Everything new with PHP 7.3Everything new with PHP 7.3
Everything new with PHP 7.3
 
Php 7.3 et ses RFC (AFUP Toulouse)
Php 7.3 et ses RFC  (AFUP Toulouse)Php 7.3 et ses RFC  (AFUP Toulouse)
Php 7.3 et ses RFC (AFUP Toulouse)
 
Tout sur PHP 7.3 et ses RFC
Tout sur PHP 7.3 et ses RFCTout sur PHP 7.3 et ses RFC
Tout sur PHP 7.3 et ses RFC
 
Review unknown code with static analysis php ipc 2018
Review unknown code with static analysis   php ipc 2018Review unknown code with static analysis   php ipc 2018
Review unknown code with static analysis php ipc 2018
 
Code review for busy people
Code review for busy peopleCode review for busy people
Code review for busy people
 

Kürzlich hochgeladen

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Kürzlich hochgeladen (20)

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Php 7 errors messages

  • 1. PHP 7.0'S ERROR MESSAGES HAVING FUN WITH ERRORS PHPAmersfoort
  • 2. AGENDA • 2229 error messages to review • New gotchas • New features, new messages
  • 3. SPEAKER • Damien Seguy • CTO at exakat • "Ik ben een boterham" : I'm a resident • Automated code audit services
  • 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 (New features) • Better linting • Removed messages • Cryptic messages
  • 11. RETURN VALUE OF %S%S%S() MUST %S%S, %S%S RETURNED <?php      function x(): array {      return false;   }      ?> Uncaught TypeError: Return value of x() must be of the type array, 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   'foo'[0] = 'b';   ?>
  • 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. 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
  • 23. CANNOT DECLARE A RETURN TYPE • __construct • __destruct • __clone • "PHP 4 constructor" <?php    class x {       function __construct() : array {           return true;       }       function x() : array {           return true;       }   }   ?>
  • 24. 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;       }   }   ?>
  • 25. INVALID UTF-8 CODEPOINT ESCAPE SEQUENCE 我爱你 <?php    $a = "u{6211}u{7231}u{4f60}";   echo $a;   ?> 
  • 26. INVALID UTF-8 CODEPOINT ESCAPE SEQUENCE • Incompatible with PHP 5.6 • Good for literals • Alternatives? <?php    $a = "u{de";   echo $a;   ?>  <?php   echo mb_convert_encoding('&#x'.$unicode.';', 'UTF-8', 'HTML-ENTITIES');   echo json_decode('"u'.$unicode.'"');   echo html_entity_decode('&#'.hexdec($unicode).';', 0, 'UTF-8');        eval('"u{'.$unicode.'}n"');   ?>
  • 28. 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 rarely useful <?php    class x {       const class = 1;   }   ?>
  • 29. 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 rarely useful • 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)
  • 30. DYNAMIC CLASS NAMES ARE NOT ALLOWED IN COMPILE-TIME ::CLASS FETCH <?php     $c = new class {  function f() {  echo $x::class;  } };  $c->f();  ?>
  • 32. SWITCH STATEMENTS MAY ONLY CONTAIN ONE DEFAULT CLAUSE <?php    switch($x) {        case '1' :             break;        default :             break;        default :             break;        case '2' :             break;    }    ?>
  • 33. 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;   
  • 34. EXCEPTIONS MUST IMPLEMENT THROWABLE <?php     throw new stdClass(); ?>  Fatal error: Uncaught Error: Cannot throw objects that do not implement Throwable
  • 38. 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 REMOVE
  • 39. 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
  • 41. 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));  ?>
  • 42. DIVISION OF PHP_INT_MIN BY -1 IS NOT AN INTEGER • PHP_INT_MIN is the smallest integer on PHP • PHP_INT_MAX : 9223372036854775807 • PHP_INT_MIN : -9223372036854775808 • Division or multiplication leads to non-integer • Uses the Integer Division intdiv()
  • 43. WEBP DECODE: REALLOC FAILED • New image format for the Web • Lossless compression, small files • gdImageCreateFromWebpCtx emit this • Probably very bad
  • 44. FUNCTION NAME MUST BE A STRING <?php   if ($_GET('X') == 'Go') {       ProcessFile();       return;   }   ?>
  • 45. ENCODING DECLARATION PRAGMA MUST BE THE VERY FIRST STATEMENT IN THE SCRIPT
  • 46. NAMESPACE DECLARATION STATEMENT HAS TO BE THE VERY FIRST STATEMENT IN THE SCRIPT
  • 47. 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
  • 49. YOU SEEM TO BE TRYING TO USE A DIFFERENT LANGUAGE... <?php   use strict;
  • 50. WHAT ABOUT MY CODE?
  • 51. 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?
  • 52. • die('I SEE ' . $action . ' - ' . $_POST['categories_id']); • die("Error: application_top not found.nMake sure you have placed the currency_cron.php 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);