略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ADD

2024-12-21

ADD

PHP code

<?php
/*
 * Adds "value1" to "value2" and stores the result into "result".
 * opcode number: 1
 */
echo 2;
?>

PHP opcodes

Function name: (null)

Compiled variables: none

line#op fetchextreturn operands
60 ADD   ~0 1,2
 1 ECHO     ~0
72 RETURN     1
add a note add a note

User Contributed Notes 3 notes

up
1
fengdingbo at gmail dot com
5 years ago
<?php
echo 1+2;
?>
qiufeng@ubuntu:~$ php -dvld.active=1 test.php
Finding entry points
Branch analysis from position: 0
Return found
filename:       /home/qiufeng/test.php
function name:  (null)
number of ops:  3
compiled vars:  none
line     # *  op                           fetch          ext  return  operands
---------------------------------------------------------------------------------
   2     0  >   ADD                                              ~0      1, 2
         1      ECHO                                                     ~0
   3     2    > RETURN                                                   1

branch: #  0; line:     2-    3; sop:     0; eop:     2
path #1: 0,
up
0
jcastromail at yahoo dot es
1 year ago
For you information
Using +0 for casting a string into a integer works but it generates a warning in php 7.1+

PHP 5.X:   "abc"+0 = 0
PHP 7.0:   "abc"+0 = 0
PHP 7.1:   "abc"+0 = 0 (Warning: A non-numeric value encountered in..)

The correct way (if you are using it for casting) is to do

PHP 7.1:   (int)"abc" = 0
up
0
hulupiao at sina dot cn
1 year ago
$ php -v
PHP 7.1.5 (cli) (built: May 13 2017 13:30:32) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.5, Copyright (c) 1999-2017, by Zend Technologies
    with Xdebug v2.5.4, Copyright (c) 2002-2017, by Derick Rethans
--------------------------------
$ cat test.php
<?php
echo 1 + 2;
--------------------------------
$
php -dvld.active=1 test.php
Finding entry points
Branch analysis from position
: 0
Jump found
. (Code = 62) Position 1 = -2
filename
:       /data/test.php
function name:  (null)
number of ops3
compiled vars
none
line    
#* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  
2     0  E >   EXT_STMT
         1       
ECHO                                                     3
   4     2     
> RETURN                                                   1

官方地址:https://www.php.net/manual/en/internals2.opcodes.add.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3