3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class ErrorPrinter { /* String to print for an error where a parameter is missing from the post */ const ERROR_MISSING_PARAM = "10000"; private $errors = array(); private $number_of_errors = 0; function addError($error, $variable){ $this->errors[$variable] = $error; $this->number_of_errors = count($this->errors); } function printToJson(){ return json_encode($this->errors); } function getNumberOfErrors(){ return $this->number_of_errors; } } $printer = new ErrorPrinter; $printer->addError(ErrorPrinter::ERROR_MISSING_PARAM, 'name'); echo $printer->getNumberOfErrors . "\r\n"; echo $printer->printToJson();
based on Bu5a7
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/1u85n
function name:  (null)
number of ops:  15
compiled vars:  !0 = $printer
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   NOP                                                      
  24     1        NEW                                              $2      :-6
         2        DO_FCALL                                      0          
         3        ASSIGN                                                   !0, $2
  25     4        INIT_METHOD_CALL                                         !0, 'addError'
         5        SEND_VAL_EX                                              '10000'
         6        SEND_VAL_EX                                              'name'
         7        DO_FCALL                                      0          
  26     8        FETCH_OBJ_R                                      $6      !0, 'getNumberOfErrors'
         9        CONCAT                                           ~7      $6, '%0D%0A'
        10        ECHO                                                     ~7
  27    11        INIT_METHOD_CALL                                         !0, 'printToJson'
        12        DO_FCALL                                      0  $8      
        13        ECHO                                                     $8
        14      > RETURN                                                   1

Class ErrorPrinter:
Function adderror:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/1u85n
function name:  addError
number of ops:  12
compiled vars:  !0 = $error, !1 = $variable
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  10     0  E >   RECV                                             !0      
         1        RECV                                             !1      
  11     2        FETCH_OBJ_W                                      $2      'errors'
         3        ASSIGN_DIM                                               $2, !1
         4        OP_DATA                                                  !0
  12     5        INIT_FCALL                                               'count'
         6        FETCH_OBJ_R                                      $5      'errors'
         7        SEND_VAR                                                 $5
         8        DO_ICALL                                         $6      
         9        ASSIGN_OBJ                                               'number_of_errors'
        10        OP_DATA                                                  $6
  13    11      > RETURN                                                   null

End of function adderror

Function printtojson:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/1u85n
function name:  printToJson
number of ops:  6
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  16     0  E >   INIT_FCALL                                               'json_encode'
         1        FETCH_OBJ_R                                      $0      'errors'
         2        SEND_VAR                                                 $0
         3        DO_ICALL                                         $1      
         4      > RETURN                                                   $1
  17     5*     > RETURN                                                   null

End of function printtojson

Function getnumberoferrors:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/1u85n
function name:  getNumberOfErrors
number of ops:  3
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  20     0  E >   FETCH_OBJ_R                                      $0      'number_of_errors'
         1      > RETURN                                                   $0
  21     2*     > RETURN                                                   null

End of function getnumberoferrors

End of class ErrorPrinter.

Generated using Vulcan Logic Dumper, using php 7.3.0