3v4l.org

run code in 300+ PHP versions simultaneously
<?php class SimpleXMLExtended extends SimpleXMLElement { public function addCData($cdata_text) { $node = dom_import_simplexml($this); $no = $node->ownerDocument; $node->appendChild($no->createCDATASection($cdata_text)); } } $oXML = new SimpleXMLExtended('<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0" />'); $oChannel = $oXML->addChild('channel'); $oChannel->addChild('title', 'TEST'); $oProduct = $oChannel->addChild('item'); $oProduct->addChild('condition1', 'new', 'http://base.google.com/ns/1.0'); $oProduct->addChild('condition2', 'new', 'http://base.google.com/ns/1.0'); $oProduct->product_type = null; $oProduct->product_type->addCData('TEST - HOW TO GET NAMESPACE HERE'); $oProduct->addChild('condition3', 'new', 'http://base.google.com/ns/1.0'); echo $oXML->asXML();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/N3jGT
function name:  (null)
number of ops:  41
compiled vars:  !0 = $oXML, !1 = $oChannel, !2 = $oProduct
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   NEW                                              $3      'SimpleXMLExtended'
          1        SEND_VAL_EX                                              '%3Crss+xmlns%3Ag%3D%22http%3A%2F%2Fbase.google.com%2Fns%2F1.0%22+version%3D%222.0%22+%2F%3E'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $3
   11     4        INIT_METHOD_CALL                                         !0, 'addChild'
          5        SEND_VAL_EX                                              'channel'
          6        DO_FCALL                                      0  $6      
          7        ASSIGN                                                   !1, $6
   12     8        INIT_METHOD_CALL                                         !1, 'addChild'
          9        SEND_VAL_EX                                              'title'
         10        SEND_VAL_EX                                              'TEST'
         11        DO_FCALL                                      0          
   14    12        INIT_METHOD_CALL                                         !1, 'addChild'
         13        SEND_VAL_EX                                              'item'
         14        DO_FCALL                                      0  $9      
         15        ASSIGN                                                   !2, $9
   15    16        INIT_METHOD_CALL                                         !2, 'addChild'
         17        SEND_VAL_EX                                              'condition1'
         18        SEND_VAL_EX                                              'new'
         19        SEND_VAL_EX                                              'http%3A%2F%2Fbase.google.com%2Fns%2F1.0'
         20        DO_FCALL                                      0          
   16    21        INIT_METHOD_CALL                                         !2, 'addChild'
         22        SEND_VAL_EX                                              'condition2'
         23        SEND_VAL_EX                                              'new'
         24        SEND_VAL_EX                                              'http%3A%2F%2Fbase.google.com%2Fns%2F1.0'
         25        DO_FCALL                                      0          
   18    26        ASSIGN_OBJ                                               !2, 'product_type'
         27        OP_DATA                                                  null
   19    28        FETCH_OBJ_R                                      ~14     !2, 'product_type'
         29        INIT_METHOD_CALL                                         ~14, 'addCData'
         30        SEND_VAL_EX                                              'TEST+-+HOW+TO+GET+NAMESPACE+HERE'
         31        DO_FCALL                                      0          
   21    32        INIT_METHOD_CALL                                         !2, 'addChild'
         33        SEND_VAL_EX                                              'condition3'
         34        SEND_VAL_EX                                              'new'
         35        SEND_VAL_EX                                              'http%3A%2F%2Fbase.google.com%2Fns%2F1.0'
         36        DO_FCALL                                      0          
   24    37        INIT_METHOD_CALL                                         !0, 'asXML'
         38        DO_FCALL                                      0  $17     
         39        ECHO                                                     $17
         40      > RETURN                                                   1

Class SimpleXMLExtended:
Function addcdata:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/N3jGT
function name:  addCData
number of ops:  15
compiled vars:  !0 = $cdata_text, !1 = $node, !2 = $no
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'dom_import_simplexml'
          2        FETCH_THIS                                       ~3      
          3        SEND_VAL                                                 ~3
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !1, $4
    5     6        FETCH_OBJ_R                                      ~6      !1, 'ownerDocument'
          7        ASSIGN                                                   !2, ~6
    6     8        INIT_METHOD_CALL                                         !1, 'appendChild'
          9        INIT_METHOD_CALL                                         !2, 'createCDATASection'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0  $8      
         12        SEND_VAR_NO_REF_EX                                       $8
         13        DO_FCALL                                      0          
    7    14      > RETURN                                                   null

End of function addcdata

End of class SimpleXMLExtended.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.5 ms | 1005 KiB | 14 Q