Skip to content

refcount实际运行结果和文档不一致 #41

Open
@shengbinxu

Description

@shengbinxu

在下面这篇文章中:
https://github.com/pangudashu/php7-internal/blob/master/2/zval.md
有个demo:

$a = "time:" . time();   //$a       ->  zend_string_1(refcount=1)
$b = $a;                 //$a,$b    ->  zend_string_1(refcount=2)
$c = $b;                 //$a,$b,$c ->  zend_string_1(refcount=3)

unset($b);               //$b = IS_UNDEF  $a,$c ->  zend_string_1(refcount=2)

我用php7.0实际运行的结果是:

<?php
$a = "time:" . time();   //$a       ->  zend_string_1(refcount=1)
debug_zval_dump($a);
$b = $a;                 //$a,$b    ->  zend_string_1(refcount=2)
$c = $b;                 //$a,$b,$c ->  zend_string_1(refcount=3)
debug_zval_dump($a);

unset($b);               //$b = IS_UNDEF  $a,$c ->  zend_string_1(refcount=2)

debug_zval_dump($a);

输出:

string(15) "time:1629940681" refcount(2)
string(15) "time:1629940681" refcount(4)
string(15) "time:1629940681" refcount(3)

想请教下,是什么原因导致了这种差异?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions