Press "Enter" to skip to content


一个问题, var_dump(1...9)输出什么?


php -r “var_dump(1...9)”;
string(4) ”10.9“

输出10.9, 乍一看这个var_dump的输出很奇怪是不是? 为什么呢?


phpdbg -n -p /tmp/1.php
function name: (null)
L1-35 {main}() /tmp/1.php - 0x7f56d1a63460 + 4 ops
L2 #0 INIT_FCALL<1> 96 "var_dump"
L2 #1 SEND_VAL "10.9" 1
L35 #3 RETURN<-1> 1

所以这么看来,早在生成opcode之前,1...9就变成了常量10.9,考虑到这是字面量,我们现在去看看zend_language_scanner.l, 找到这么一行:

DNUM ({LNUM}?"."{LNUM})|({LNUM}"."{LNUM}?)

1...9 会被依次接受为: 1. (浮点数1), 然后是 . (字符串连接符号) 然后是.9(浮点数0.9)

所以在编译阶段就会直接生成 “1” . “0.9” -> 字符串的字面量”10.9”


当然这个也不仅仅是PHP会这么定义了,几乎所有的语言都会定义这种缩写浮点数都形式. C语言中有的时候我们为了输入一个浮点型的整形,就可以采用比如 1. 来告诉编译器这是个浮点数.

只不过,一来刚好在PHP中.号还有另外一层含义就是字符串连接,二来...在PHP5.6之后是个新的操作符叫做Splat operator, 可以用来定义可变参数函数,或者解数组,比如,


function  foo($a, $b, $c) {
        var_dump($a + $b + $c);

$parameters = array (1, 2, 3);


所以, 乍一看才会导致了这个看起来很困惑的结果, 🙂


  1. upload image
    upload image May 3, 2023

    Your email address will not be published. Required fields are marked *

  2. Shriram Poem
    Shriram Poem April 29, 2023

    Shriram The Poem is the ideal choice for modern families looking for a luxurious and fulfilling lifestyle in the heart of Bangalore.

  3. Godrej Splendour
    Godrej Splendour March 21, 2023

    Godrej Splendour is a premium residential project located in the heart of Bangalore’s bustling suburb, Whitefield.

  4. Sobha Neopolis
    Sobha Neopolis March 21, 2023

    Sobha Neopolis is a leading real estate company in Bangalore. Everyone dreams of having their own home and many have helped make their dreams come true. They carefully build each home with an emphasis on quality, practical details, and value for money.They want to gain people’s trust and confidence while launching new products and services.

  5. t rex game
    t rex game January 30, 2021

    I should express that I like this article so a ton and moreover using it in regular. I believe you would continue sharing better than average article here.

  6. c
    c December 22, 2020


  7. maple
    maple June 29, 2020

    无力吐槽 (

  8. phper
    phper April 7, 2020

    这样写代码会被看你代码的人骂的,所以还是不要这样写…… ^_^

  9. 阿毛
    阿毛 March 27, 2020


  10. 沈唁志
    沈唁志 February 25, 2020


    • laruence
      laruence February 25, 2020

      wordpress特别2 , 自动转

    • jaggle
      jaggle July 27, 2020


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.