3v4l.org

run code in 300+ PHP versions simultaneously
<?php $testString = 'scary ghost'; echo "She saw a $testString. It was green!" . PHP_EOL; //embed newline with /n echo "She saw a $testString. It was blue!\n"; $fruit = array('apple', 'banana', 'orange', 'grape'); echo "I ate one $fruit[0] for breakfast, and one $fruit[2] for lunch\n"; // Interpolating an array with a string constant key $name = array('first' => 'George', 'last' => 'Washington'); // Syntax error //echo "The first US President was $name['first'] $name['last']\n"; // Using complex syntax echo "The first US President was {$name['first']} {$name['last']}\n"; $linkData = array('url' =>'http://www.phpfreaks.com', 'name' => 'phpFreaks'); $linkConcatenate = '<a href="' . $linkData['url'] . "'>" . $linkData['name'] . '</a>' . PHP_EOL; $linkInterpolate = "<a href='{$linkData['url']}'>{$linkData['name']}</a>\n"; echo "PHP questions answered at $linkConcatenate <br>\n"; echo "PHP questions answered at $linkInterpolate <br>\n"; class Person { private $name; private $age; private $title; public $summary; public function __construct($name, $title, $age) { $this->name = $name; $this->age = $age; $this->title = $title; $this->summary = $this->__tostring(); } public function __tostring() { return "Name: {$this->name}. Age: {$this->age}. Title: {$this->title}"; } public function getName() { return $this->name; } public function getAge() { return $this->age; } } $bob = new Person('Bob Smith', 'Manager', 31); $sue = new Person('Sue Jones', 'Director', 28); echo "Bob's Summary| {$bob->summary}\n"; echo "Sue's Summary| {$sue->summary}\n"; echo " <table> <tr><th>Employee</th></tr> <tr><td>$bob</td></tr> <tr><td>$sue</td></tr> </table>"; $employees[] = $bob; $employees[] = $sue; echo "\n\n\n"; foreach ($employees as $employee) { echo "{$employee->getName()} is {$employee->getAge()} years old\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 88, Position 2 = 99
Branch analysis from position: 88
2 jumps found. (Code = 78) Position 1 = 89, Position 2 = 99
Branch analysis from position: 89
1 jumps found. (Code = 42) Position 1 = 88
Branch analysis from position: 88
Branch analysis from position: 99
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 99
filename:       /in/7jUPS
function name:  (null)
number of ops:  101
compiled vars:  !0 = $testString, !1 = $fruit, !2 = $name, !3 = $linkData, !4 = $linkConcatenate, !5 = $linkInterpolate, !6 = $bob, !7 = $sue, !8 = $employees, !9 = $employee
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'scary+ghost'
    4     1        ROPE_INIT                                     3  ~12     'She+saw+a+'
          2        ROPE_ADD                                      1  ~12     ~12, !0
          3        ROPE_END                                      2  ~11     ~12, '.++It+was+green%21'
          4        CONCAT                                           ~14     ~11, '%0A'
          5        ECHO                                                     ~14
    7     6        ROPE_INIT                                     3  ~16     'She+saw+a+'
          7        ROPE_ADD                                      1  ~16     ~16, !0
          8        ROPE_END                                      2  ~15     ~16, '.++It+was+blue%21%0A'
          9        ECHO                                                     ~15
    9    10        ASSIGN                                                   !1, <array>
   11    11        ROPE_INIT                                     5  ~22     'I+ate+one+'
         12        FETCH_DIM_R                                      ~19     !1, 0
         13        ROPE_ADD                                      1  ~22     ~22, ~19
         14        ROPE_ADD                                      2  ~22     ~22, '+for+breakfast%2C+and+one+'
         15        FETCH_DIM_R                                      ~20     !1, 2
         16        ROPE_ADD                                      3  ~22     ~22, ~20
         17        ROPE_END                                      4  ~21     ~22, '+for+lunch%0A'
         18        ECHO                                                     ~21
   15    19        ASSIGN                                                   !2, <array>
   21    20        ROPE_INIT                                     5  ~29     'The+first+US+President+was+'
         21        FETCH_DIM_R                                      ~26     !2, 'first'
         22        ROPE_ADD                                      1  ~29     ~29, ~26
         23        ROPE_ADD                                      2  ~29     ~29, '+'
         24        FETCH_DIM_R                                      ~27     !2, 'last'
         25        ROPE_ADD                                      3  ~29     ~29, ~27
         26        ROPE_END                                      4  ~28     ~29, '%0A'
         27        ECHO                                                     ~28
   23    28        ASSIGN                                                   !3, <array>
   25    29        FETCH_DIM_R                                      ~33     !3, 'url'
         30        CONCAT                                           ~34     '%3Ca+href%3D%22', ~33
         31        CONCAT                                           ~35     ~34, '%27%3E'
         32        FETCH_DIM_R                                      ~36     !3, 'name'
         33        CONCAT                                           ~37     ~35, ~36
         34        CONCAT                                           ~38     ~37, '%3C%2Fa%3E'
         35        CONCAT                                           ~39     ~38, '%0A'
         36        ASSIGN                                                   !4, ~39
   27    37        ROPE_INIT                                     5  ~44     '%3Ca+href%3D%27'
         38        FETCH_DIM_R                                      ~41     !3, 'url'
         39        ROPE_ADD                                      1  ~44     ~44, ~41
         40        ROPE_ADD                                      2  ~44     ~44, '%27%3E'
         41        FETCH_DIM_R                                      ~42     !3, 'name'
         42        ROPE_ADD                                      3  ~44     ~44, ~42
         43        ROPE_END                                      4  ~43     ~44, '%3C%2Fa%3E%0A'
         44        ASSIGN                                                   !5, ~43
   29    45        ROPE_INIT                                     3  ~49     'PHP+questions+answered+at+'
         46        ROPE_ADD                                      1  ~49     ~49, !4
         47        ROPE_END                                      2  ~48     ~49, '+%3Cbr%3E%0A'
         48        ECHO                                                     ~48
   30    49        ROPE_INIT                                     3  ~52     'PHP+questions+answered+at+'
         50        ROPE_ADD                                      1  ~52     ~52, !5
         51        ROPE_END                                      2  ~51     ~52, '+%3Cbr%3E%0A'
         52        ECHO                                                     ~51
   33    53        DECLARE_CLASS                                            'person'
   59    54        NEW                                              $54     'Person'
         55        SEND_VAL_EX                                              'Bob+Smith'
         56        SEND_VAL_EX                                              'Manager'
         57        SEND_VAL_EX                                              31
         58        DO_FCALL                                      0          
         59        ASSIGN                                                   !6, $54
   60    60        NEW                                              $57     'Person'
         61        SEND_VAL_EX                                              'Sue+Jones'
         62        SEND_VAL_EX                                              'Director'
         63        SEND_VAL_EX                                              28
         64        DO_FCALL                                      0          
         65        ASSIGN                                                   !7, $57
   62    66        ROPE_INIT                                     3  ~62     'Bob%27s+Summary%7C+'
         67        FETCH_OBJ_R                                      ~60     !6, 'summary'
         68        ROPE_ADD                                      1  ~62     ~62, ~60
         69        ROPE_END                                      2  ~61     ~62, '%0A'
         70        ECHO                                                     ~61
   63    71        ROPE_INIT                                     3  ~66     'Sue%27s+Summary%7C+'
         72        FETCH_OBJ_R                                      ~64     !7, 'summary'
         73        ROPE_ADD                                      1  ~66     ~66, ~64
         74        ROPE_END                                      2  ~65     ~66, '%0A'
         75        ECHO                                                     ~65
   65    76        ROPE_INIT                                     5  ~69     '%0A%3Ctable%3E%0A++++++++%3Ctr%3E%3Cth%3EEmployee%3C%2Fth%3E%3C%2Ftr%3E%0A++++++++%3Ctr%3E%3Ctd%3E'
   68    77        ROPE_ADD                                      1  ~69     ~69, !6
         78        ROPE_ADD                                      2  ~69     ~69, '%3C%2Ftd%3E%3C%2Ftr%3E%0A++++++++%3Ctr%3E%3Ctd%3E'
   69    79        ROPE_ADD                                      3  ~69     ~69, !7
         80        ROPE_END                                      4  ~68     ~69, '%3C%2Ftd%3E%3C%2Ftr%3E%0A%3C%2Ftable%3E'
         81        ECHO                                                     ~68
   73    82        ASSIGN_DIM                                               !8
         83        OP_DATA                                                  !6
   74    84        ASSIGN_DIM                                               !8
         85        OP_DATA                                                  !7
   76    86        ECHO                                                     '%0A%0A%0A'
   78    87      > FE_RESET_R                                       $74     !8, ->99
         88    > > FE_FETCH_R                                               $74, !9, ->99
   79    89    >   INIT_METHOD_CALL                                         !9, 'getName'
         90        DO_FCALL                                      0  $75     
         91        ROPE_INIT                                     4  ~78     $75
         92        ROPE_ADD                                      1  ~78     ~78, '+is+'
         93        INIT_METHOD_CALL                                         !9, 'getAge'
         94        DO_FCALL                                      0  $76     
         95        ROPE_ADD                                      2  ~78     ~78, $76
         96        ROPE_END                                      3  ~77     ~78, '+years+old%0A'
         97        ECHO                                                     ~77
   78    98      > JMP                                                      ->88
         99    >   FE_FREE                                                  $74
   81   100      > RETURN                                                   1

Class Person:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7jUPS
function name:  __construct
number of ops:  14
compiled vars:  !0 = $name, !1 = $title, !2 = $age
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   40     3        ASSIGN_OBJ                                               'name'
          4        OP_DATA                                                  !0
   41     5        ASSIGN_OBJ                                               'age'
          6        OP_DATA                                                  !2
   42     7        ASSIGN_OBJ                                               'title'
          8        OP_DATA                                                  !1
   43     9        INIT_METHOD_CALL                                         '__tostring'
         10        DO_FCALL                                      0  $7      
         11        ASSIGN_OBJ                                               'summary'
         12        OP_DATA                                                  $7
   44    13      > RETURN                                                   null

End of function __construct

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7jUPS
function name:  __tostring
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   ROPE_INIT                                     6  ~4      'Name%3A+'
          1        FETCH_OBJ_R                                      ~0      'name'
          2        ROPE_ADD                                      1  ~4      ~4, ~0
          3        ROPE_ADD                                      2  ~4      ~4, '.+Age%3A+'
          4        FETCH_OBJ_R                                      ~1      'age'
          5        ROPE_ADD                                      3  ~4      ~4, ~1
          6        ROPE_ADD                                      4  ~4      ~4, '.++Title%3A+'
          7        FETCH_OBJ_R                                      ~2      'title'
          8        ROPE_END                                      5  ~3      ~4, ~2
          9        VERIFY_RETURN_TYPE                                       ~3
         10      > RETURN                                                   ~3
   48    11*       VERIFY_RETURN_TYPE                                       
         12*     > RETURN                                                   null

End of function __tostring

Function getname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7jUPS
function name:  getName
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   FETCH_OBJ_R                                      ~0      'name'
          1      > RETURN                                                   ~0
   52     2*     > RETURN                                                   null

End of function getname

Function getage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7jUPS
function name:  getAge
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   FETCH_OBJ_R                                      ~0      'age'
          1      > RETURN                                                   ~0
   56     2*     > RETURN                                                   null

End of function getage

End of class Person.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.51 ms | 1407 KiB | 13 Q