3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Developer: Felipe Francisco * Reference: admin@felipefrancisco.com.br * Date: 10/10/2012 */ class o extends Model { /** * Tipo de saída como HTML. * @var [boolean] */ protected $_HtmlOut = false; /** * Contagem de Atributos reais (previamente declarados) existentes. * @var [int] */ protected $_RealAttrs; /** * Inicia o objeto. * @param [string] $table [Nome da tabela que será carregada em um objeto] * @param [int] $id [Id para ser carregado juntamente, na criação da tabela.] */ function __construct($table, $id = NULL) { # Inicia a instância de banco de dados. if(!Model::db) parent::_Instance(); # Verfica na memória se o objeto já foi iniciado anteriormente. Se sim, retorne-o. if(self::$_Cache[$table][$id] instanceof o) return self::$_Cache[$table][$id]; # Armazena o nome da tabela. $this->setTable($table); # Conta os atributos reais da classe para efeito de cálculo de campos posteriormente. $this->_realAttrs(); # Gera os atributos virtuais; $this->_virtAttrs(); if(!is_null($id)) $this->Select($id); } /** * Valida as saídas da classe, sempre impimindo em formato HTML. * @param [string] $var Representa um atributo virtual da tabela. * @return [mixed] Valor correspondente ao atributo selecionado. */ public function __get($var) { # Verifica se o atributo existe dentro dos atributos virutais. if(in_array($var, $this->_Fields)) { # Caso a saída HTML seja verdadeira, formataremos a variável. if($this->_HtmlOut) return Format::HTML($this->{$var}); else return $this->{$var}; } else throw new Exception("Atributo ". $var ." da tabela ". $this->_Table ." não encontrado."); } /** * Conta os atributos reais da classe para efeito de cálculo de campos posteriormente. */ private function _realAttrs() { # Procura atributos previamente declarados e define a quantidade de atributos previamente declarados na classe. foreach(get_object_vars($this) as $vars) $this->_RealAttrs++; } /** * Define os atributos virtuais da classe. */ private function _virtAttrs() { # Consulta para exibir os campos da tabela em questão. $query = "SHOW COLUMNS FROM ". $this->table; # Execução da Consulta de exibição de campos da tabela. $result = self::q($query); # Caso existam campos na tabela, prossiga: if ($result) { # Enquanto existirem colunas, faça: foreach ($result as $row) { # Cria atributo virtual. $this->{$row['Field']} = null; # Acha a posição que representa o fim do nome do Tipo do Campo. $strpos = strpos($row['Type'],'('); # Define as Meta-características do campo. $this->_Meta[$row['Field']] = ($strpos) ? substr($row['Type'], 0, $strpos) : $row['Type']; # Armazena o campo na lista de Campos. $this->_Fields[] = $row['Field']; if($row['Null'] == 'YES'); $this->_NotNull[] = $row['Field']; } } else throw new Exception("Tabela ". $this->_Table ." não encontrada."); } /** * Reseta a classe. */ private function _ResetAll() { $this->_ResetFields(); $this->HtmlOutput(false); unset( $this->_Table, $this->_RealAttrs, $this->_Meta, $this->_NotNull, $this->_Fields ); } /** * Define o tipo de saída de dados da classe como HTML * @param [boolean] $mode ativa ou desativa a saída HTML */ public function HtmlOutput($mode = true) { # Valida o modo de saída. if(!is_bool($mode)) throw new Exception('Modo de HTML inválido'); # Define a saída de variáveis no modo HTML. $this->_HtmlOut = $mode; } /** * Reseta os campos virtuais. */ protected function _ResetFields() { if(is_array($this->_Fields)) foreach($this->_Fields as $Field) $this->{$Field} = null; else throw new Exception('Não há campos para limpar neste objeto: ' . var_export($this, true)); } } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OGkEJ
function name:  (null)
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   DECLARE_CLASS                                            'o', 'model'
  170     1      > RETURN                                                   1

Class o:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 29
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
Branch analysis from position: 7
filename:       /in/OGkEJ
function name:  __construct
number of ops:  30
compiled vars:  !0 = $table, !1 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   31     2        FETCH_CLASS_CONSTANT                             ~2      'Model', 'db'
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->7
   32     5    >   INIT_STATIC_METHOD_CALL                                  '_Instance'
          6        DO_FCALL                                      0          
   35     7    >   FETCH_STATIC_PROP_R          unknown             ~5      '_Cache'
          8        FETCH_DIM_R                                      ~6      ~5, !0
          9        FETCH_DIM_R                                      ~7      ~6, !1
         10        INSTANCEOF                                               ~7, 'o'
         11      > JMPZ                                                     ~8, ->16
   36    12    >   FETCH_STATIC_PROP_R          unknown             ~9      '_Cache'
         13        FETCH_DIM_R                                      ~10     ~9, !0
         14        FETCH_DIM_R                                      ~11     ~10, !1
         15      > RETURN                                                   ~11
   39    16    >   INIT_METHOD_CALL                                         'setTable'
         17        SEND_VAR_EX                                              !0
         18        DO_FCALL                                      0          
   42    19        INIT_METHOD_CALL                                         '_realAttrs'
         20        DO_FCALL                                      0          
   45    21        INIT_METHOD_CALL                                         '_virtAttrs'
         22        DO_FCALL                                      0          
   47    23        TYPE_CHECK                                    2  ~15     !1
         24        BOOL_NOT                                         ~16     ~15
         25      > JMPZ                                                     ~16, ->29
   48    26    >   INIT_METHOD_CALL                                         'Select'
         27        SEND_VAR_EX                                              !1
         28        DO_FCALL                                      0          
   49    29    > > RETURN                                                   null

End of function __construct

Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 19
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 16
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/OGkEJ
function name:  __get
number of ops:  29
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
   59     1        INIT_FCALL                                               'in_array'
          2        SEND_VAR                                                 !0
          3        FETCH_OBJ_R                                      ~1      '_Fields'
          4        SEND_VAL                                                 ~1
          5        DO_ICALL                                         $2      
          6      > JMPZ                                                     $2, ->19
   62     7    >   FETCH_OBJ_R                                      ~3      '_HtmlOut'
          8      > JMPZ                                                     ~3, ->16
   63     9    >   INIT_STATIC_METHOD_CALL                                  'Format', 'HTML'
         10        CHECK_FUNC_ARG                                           
         11        FETCH_OBJ_FUNC_ARG                               $4      !0
         12        SEND_FUNC_ARG                                            $4
         13        DO_FCALL                                      0  $5      
         14      > RETURN                                                   $5
         15*       JMP                                                      ->18
   65    16    >   FETCH_OBJ_R                                      ~6      !0
         17      > RETURN                                                   ~6
         18*       JMP                                                      ->28
   68    19    >   NEW                                              $7      'Exception'
         20        CONCAT                                           ~8      'Atributo+', !0
         21        CONCAT                                           ~9      ~8, '+da+tabela+'
         22        FETCH_OBJ_R                                      ~10     '_Table'
         23        CONCAT                                           ~11     ~9, ~10
         24        CONCAT                                           ~12     ~11, '+n%C3%A3o+encontrado.'
         25        SEND_VAL_EX                                              ~12
         26        DO_FCALL                                      0          
         27      > THROW                                         0          $7
   69    28*     > RETURN                                                   null

End of function __get

Function _realattrs:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/OGkEJ
function name:  _realAttrs
number of ops:  10
compiled vars:  !0 = $vars
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   INIT_FCALL                                               'get_object_vars'
          1        FETCH_THIS                                       ~1      
          2        SEND_VAL                                                 ~1
          3        DO_ICALL                                         $2      
          4      > FE_RESET_R                                       $3      $2, ->8
          5    > > FE_FETCH_R                                               $3, !0, ->8
   79     6    >   PRE_INC_OBJ                                              '_RealAttrs'
   78     7      > JMP                                                      ->5
          8    >   FE_FREE                                                  $3
   80     9      > RETURN                                                   null

End of function _realattrs

Function _virtattrs:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 48
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 46
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 46
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 29
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 41
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 41
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 41
Branch analysis from position: 41
Branch analysis from position: 41
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
Branch analysis from position: 48
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/OGkEJ
function name:  _virtAttrs
number of ops:  56
compiled vars:  !0 = $query, !1 = $result, !2 = $row, !3 = $strpos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   88     0  E >   FETCH_OBJ_R                                      ~4      'table'
          1        CONCAT                                           ~5      'SHOW+COLUMNS+FROM+', ~4
          2        ASSIGN                                                   !0, ~5
   91     3        INIT_STATIC_METHOD_CALL                                  'q'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0  $7      
          6        ASSIGN                                                   !1, $7
   94     7      > JMPZ                                                     !1, ->48
   97     8    > > FE_RESET_R                                       $9      !1, ->46
          9    > > FE_FETCH_R                                               $9, !2, ->46
  100    10    >   FETCH_DIM_R                                      ~10     !2, 'Field'
         11        ASSIGN_OBJ                                               ~10
         12        OP_DATA                                                  null
  103    13        INIT_FCALL                                               'strpos'
         14        FETCH_DIM_R                                      ~12     !2, 'Type'
         15        SEND_VAL                                                 ~12
         16        SEND_VAL                                                 '%28'
         17        DO_ICALL                                         $13     
         18        ASSIGN                                                   !3, $13
  106    19        FETCH_DIM_R                                      ~16     !2, 'Field'
         20      > JMPZ                                                     !3, ->29
         21    >   INIT_FCALL                                               'substr'
         22        FETCH_DIM_R                                      ~18     !2, 'Type'
         23        SEND_VAL                                                 ~18
         24        SEND_VAL                                                 0
         25        SEND_VAR                                                 !3
         26        DO_ICALL                                         $19     
         27        QM_ASSIGN                                        ~20     $19
         28      > JMP                                                      ->31
         29    >   FETCH_DIM_R                                      ~21     !2, 'Type'
         30        QM_ASSIGN                                        ~20     ~21
         31    >   FETCH_OBJ_W                                      $15     '_Meta'
         32        ASSIGN_DIM                                               $15, ~16
         33        OP_DATA                                                  ~20
  109    34        FETCH_DIM_R                                      ~24     !2, 'Field'
         35        FETCH_OBJ_W                                      $22     '_Fields'
         36        ASSIGN_DIM                                               $22
         37        OP_DATA                                                  ~24
  111    38        FETCH_DIM_R                                      ~25     !2, 'Null'
         39        IS_EQUAL                                                 ~25, 'YES'
         40      > JMPZ                                                     ~26, ->41
  112    41    >   FETCH_DIM_R                                      ~29     !2, 'Field'
         42        FETCH_OBJ_W                                      $27     '_NotNull'
         43        ASSIGN_DIM                                               $27
         44        OP_DATA                                                  ~29
   97    45      > JMP                                                      ->9
         46    >   FE_FREE                                                  $9
         47      > JMP                                                      ->55
  117    48    >   NEW                                              $30     'Exception'
         49        FETCH_OBJ_R                                      ~31     '_Table'
         50        CONCAT                                           ~32     'Tabela+', ~31
         51        CONCAT                                           ~33     ~32, '+n%C3%A3o+encontrada.'
         52        SEND_VAL_EX                                              ~33
         53        DO_FCALL                                      0          
         54      > THROW                                         0          $30
  118    55    > > RETURN                                                   null

End of function _virtattrs

Function _resetall:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OGkEJ
function name:  _ResetAll
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  126     0  E >   INIT_METHOD_CALL                                         '_ResetFields'
          1        DO_FCALL                                      0          
  128     2        INIT_METHOD_CALL                                         'HtmlOutput'
          3        SEND_VAL_EX                                              <false>
          4        DO_FCALL                                      0          
  131     5        UNSET_OBJ                                                '_Table'
  132     6        UNSET_OBJ                                                '_RealAttrs'
  133     7        UNSET_OBJ                                                '_Meta'
  134     8        UNSET_OBJ                                                '_NotNull'
  135     9        UNSET_OBJ                                                '_Fields'
  138    10      > RETURN                                                   null

End of function _resetall

Function htmloutput:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OGkEJ
function name:  HtmlOutput
number of ops:  11
compiled vars:  !0 = $mode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  144     0  E >   RECV_INIT                                        !0      <true>
  147     1        TYPE_CHECK                                   12  ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ                                                     ~2, ->8
  148     4    >   NEW                                              $3      'Exception'
          5        SEND_VAL_EX                                              'Modo+de+HTML+inv%C3%A1lido'
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $3
  151     8    >   ASSIGN_OBJ                                               '_HtmlOut'
          9        OP_DATA                                                  !0
  152    10      > RETURN                                                   null

End of function htmloutput

Function _resetfields:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
Branch analysis from position: 11
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/OGkEJ
function name:  _ResetFields
number of ops:  22
compiled vars:  !0 = $Field
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  160     0  E >   FETCH_OBJ_R                                      ~1      '_Fields'
          1        TYPE_CHECK                                  128          ~1
          2      > JMPZ                                                     ~2, ->11
  161     3    >   FETCH_OBJ_R                                      ~3      '_Fields'
          4      > FE_RESET_R                                       $4      ~3, ->9
          5    > > FE_FETCH_R                                               $4, !0, ->9
  162     6    >   ASSIGN_OBJ                                               !0
          7        OP_DATA                                                  null
  161     8      > JMP                                                      ->5
          9    >   FE_FREE                                                  $4
         10      > JMP                                                      ->21
  164    11    >   NEW                                              $6      'Exception'
         12        INIT_FCALL                                               'var_export'
         13        FETCH_THIS                                       ~7      
         14        SEND_VAL                                                 ~7
         15        SEND_VAL                                                 <true>
         16        DO_ICALL                                         $8      
         17        CONCAT                                           ~9      'N%C3%A3o+h%C3%A1+campos+para+limpar+neste+objeto%3A+', $8
         18        SEND_VAL_EX                                              ~9
         19        DO_FCALL                                      0          
         20      > THROW                                         0          $6
  166    21    > > RETURN                                                   null

End of function _resetfields

End of class o.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.53 ms | 1416 KiB | 23 Q