3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Conta { private $titular; //atributos ou dados. private float $saldo; private static $numeroDeContas = 0; public function __construct($titular)//metodos ou ações { $this ->titular = $titular; // $this referencia o objeto q chama a função $this ->saldo = 0; self::$numeroDeContas++; } public function sacar(float $valorASacar): void { if ($valorASacar > $this->saldo) { echo "Saldo indisponível"; return; } $this->saldo -= $valorASacar; } public function depositar(float $valorADepositar): void { if ($valorADepositar < 0) { echo "Valor precisa ser positivo"; return; } $this->saldo += $valorADepositar; } public function transferir(float $valorATransferir, Conta $contaDestino): void { if ($valorATransferir > $this->saldo) { echo "Saldo indisponível"; return; } $this->sacar($valorATransferir); $contaDestino->transferir($valorATransferir); } // Métodos Recuperar. public function recuperarSaldo(): float { return $this->saldo; } public function recuperarNomeTitular(): string { return $this->titular->recuperarNome(); } public function recuperarCpfTitular(): string { return $this->titular->recuperarCpf(); } //... código omitido public static function recuperarNumeroDeContas(): int { return Conta::$numeroDeContas; } } class Titular { private string $cpf; private string $nome; public function __construct(string $cpf, string $nome) { $this->cpf = $cpf; $this->validarNomeTitular($nome); $this->nome = $nome; } private function validarNomeTitular(string $nomeTitular) { if (strlen($nomeTitular) < 5) { // strlen = tamanho da string echo "Nome precisa ter pelo menos 5 caracteres"; exit(); } } public function recuperarCpf() { return $this->cpf; } public function recuperarNome() { return $this->nome; } } $primeiraConta = new conta(new titular('123.456.789-10','Thiago Felipe')); $segundaConta = new conta(new titular('987.456.123-01', 'Aline Torres')); var_dump($primeiraConta); var_dump($segundaConta); $primeiraConta -> depositar(1000); $segundaConta -> depositar (3500); echo $primeiraConta -> recuperarNomeTitular() . PHP_EOL; echo $primeiraConta -> recuperarCpfTitular() . PHP_EOL; echo $primeiraConta -> recuperarSaldo() . PHP_EOL; echo $segundaConta -> recuperarSaldo() . PHP_EOL; echo $segundaConta -> recuperarNomeTitular() . PHP_EOL; echo $segundaConta -> recuperarCpfTitular() . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OuaDT
function name:  (null)
number of ops:  53
compiled vars:  !0 = $primeiraConta, !1 = $segundaConta
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  105     0  E >   NEW                                              $2      'conta'
          1        NEW                                              $3      'titular'
          2        SEND_VAL_EX                                              '123.456.789-10'
          3        SEND_VAL_EX                                              'Thiago+Felipe'
          4        DO_FCALL                                      0          
          5        SEND_VAR_NO_REF_EX                                       $3
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $2
  106     8        NEW                                              $7      'conta'
          9        NEW                                              $8      'titular'
         10        SEND_VAL_EX                                              '987.456.123-01'
         11        SEND_VAL_EX                                              'Aline+Torres'
         12        DO_FCALL                                      0          
         13        SEND_VAR_NO_REF_EX                                       $8
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !1, $7
  107    16        INIT_FCALL                                               'var_dump'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                                 
  108    19        INIT_FCALL                                               'var_dump'
         20        SEND_VAR                                                 !1
         21        DO_ICALL                                                 
  110    22        INIT_METHOD_CALL                                         !0, 'depositar'
         23        SEND_VAL_EX                                              1000
         24        DO_FCALL                                      0          
  111    25        INIT_METHOD_CALL                                         !1, 'depositar'
         26        SEND_VAL_EX                                              3500
         27        DO_FCALL                                      0          
  114    28        INIT_METHOD_CALL                                         !0, 'recuperarNomeTitular'
         29        DO_FCALL                                      0  $16     
         30        CONCAT                                           ~17     $16, '%0A'
         31        ECHO                                                     ~17
  115    32        INIT_METHOD_CALL                                         !0, 'recuperarCpfTitular'
         33        DO_FCALL                                      0  $18     
         34        CONCAT                                           ~19     $18, '%0A'
         35        ECHO                                                     ~19
  116    36        INIT_METHOD_CALL                                         !0, 'recuperarSaldo'
         37        DO_FCALL                                      0  $20     
         38        CONCAT                                           ~21     $20, '%0A'
         39        ECHO                                                     ~21
  118    40        INIT_METHOD_CALL                                         !1, 'recuperarSaldo'
         41        DO_FCALL                                      0  $22     
         42        CONCAT                                           ~23     $22, '%0A'
         43        ECHO                                                     ~23
  119    44        INIT_METHOD_CALL                                         !1, 'recuperarNomeTitular'
         45        DO_FCALL                                      0  $24     
         46        CONCAT                                           ~25     $24, '%0A'
         47        ECHO                                                     ~25
  120    48        INIT_METHOD_CALL                                         !1, 'recuperarCpfTitular'
         49        DO_FCALL                                      0  $26     
         50        CONCAT                                           ~27     $26, '%0A'
         51        ECHO                                                     ~27
  121    52      > RETURN                                                   1

Class Conta:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OuaDT
function name:  __construct
number of ops:  7
compiled vars:  !0 = $titular
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   11     1        ASSIGN_OBJ                                               'titular'
          2        OP_DATA                                                  !0
   12     3        ASSIGN_OBJ                                               'saldo'
          4        OP_DATA                                                  0
   14     5        PRE_INC_STATIC_PROP                                      'numeroDeContas'
   15     6      > RETURN                                                   null

End of function __construct

Function sacar:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OuaDT
function name:  sacar
number of ops:  9
compiled vars:  !0 = $valorASacar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   19     1        FETCH_OBJ_R                                      ~1      'saldo'
          2        IS_SMALLER                                               ~1, !0
          3      > JMPZ                                                     ~2, ->6
   20     4    >   ECHO                                                     'Saldo+indispon%C3%ADvel'
   21     5      > RETURN                                                   null
   24     6    >   ASSIGN_OBJ_OP                                 2          'saldo'
          7        OP_DATA                                                  !0
   25     8      > RETURN                                                   null

End of function sacar

Function depositar:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OuaDT
function name:  depositar
number of ops:  8
compiled vars:  !0 = $valorADepositar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   29     1        IS_SMALLER                                               !0, 0
          2      > JMPZ                                                     ~1, ->5
   30     3    >   ECHO                                                     'Valor+precisa+ser+positivo'
   31     4      > RETURN                                                   null
   34     5    >   ASSIGN_OBJ_OP                                 1          'saldo'
          6        OP_DATA                                                  !0
   35     7      > RETURN                                                   null

End of function depositar

Function transferir:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OuaDT
function name:  transferir
number of ops:  14
compiled vars:  !0 = $valorATransferir, !1 = $contaDestino
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   39     2        FETCH_OBJ_R                                      ~2      'saldo'
          3        IS_SMALLER                                               ~2, !0
          4      > JMPZ                                                     ~3, ->7
   40     5    >   ECHO                                                     'Saldo+indispon%C3%ADvel'
   41     6      > RETURN                                                   null
   44     7    >   INIT_METHOD_CALL                                         'sacar'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0          
   45    10        INIT_METHOD_CALL                                         !1, 'transferir'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0          
   46    13      > RETURN                                                   null

End of function transferir

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

End of function recuperarsaldo

Function recuperarnometitular:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OuaDT
function name:  recuperarNomeTitular
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   FETCH_OBJ_R                                      ~0      'titular'
          1        INIT_METHOD_CALL                                         ~0, 'recuperarNome'
          2        DO_FCALL                                      0  $1      
          3        VERIFY_RETURN_TYPE                                       $1
          4      > RETURN                                                   $1
   58     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function recuperarnometitular

Function recuperarcpftitular:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OuaDT
function name:  recuperarCpfTitular
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   FETCH_OBJ_R                                      ~0      'titular'
          1        INIT_METHOD_CALL                                         ~0, 'recuperarCpf'
          2        DO_FCALL                                      0  $1      
          3        VERIFY_RETURN_TYPE                                       $1
          4      > RETURN                                                   $1
   63     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function recuperarcpftitular

Function recuperarnumerodecontas:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OuaDT
function name:  recuperarNumeroDeContas
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'numeroDeContas'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   70     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function recuperarnumerodecontas

End of class Conta.

Class Titular:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OuaDT
function name:  __construct
number of ops:  10
compiled vars:  !0 = $cpf, !1 = $nome
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   81     2        ASSIGN_OBJ                                               'cpf'
          3        OP_DATA                                                  !0
   82     4        INIT_METHOD_CALL                                         'validarNomeTitular'
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0          
   83     7        ASSIGN_OBJ                                               'nome'
          8        OP_DATA                                                  !1
   84     9      > RETURN                                                   null

End of function __construct

Function validarnometitular:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OuaDT
function name:  validarNomeTitular
number of ops:  7
compiled vars:  !0 = $nomeTitular
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   86     0  E >   RECV                                             !0      
   88     1        STRLEN                                           ~1      !0
          2        IS_SMALLER                                               ~1, 5
          3      > JMPZ                                                     ~2, ->6
   89     4    >   ECHO                                                     'Nome+precisa+ter+pelo+menos+5+caracteres'
   90     5      > EXIT                                                     
   92     6    > > RETURN                                                   null

End of function validarnometitular

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

End of function recuperarcpf

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

End of function recuperarnome

End of class Titular.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.78 ms | 1015 KiB | 14 Q