LoginSignup
0
0

More than 3 years have passed since last update.

PHPマニュアル「参照カウント法の原理」ページのサンプルコード出力が,マニュアル記載のものと異なる

Last updated at Posted at 2020-10-17

発生した問題

マニュアルと,手元のコードの実行結果が食い違う

以下のコードです.
https://www.php.net/manual/ja/features.gc.refcounting-basics.php

<?php
$a = "new string";
xdebug_debug_zval('a');
?>

マニュアル記載の出力は以下のようになります.

a: (refcount=2, is_ref=0)='new string'

実際の出力は以下のようになります.

a: (interned, is_ref=0)='new string'

refcountの数値の変動を確認したいのに,これでは困ります.

原因

Xdebugのバージョンアップに伴う仕様変更とのことです.
手元のXdebugのバージョンを確認すると,"2.9.7-dev" でした.

$ php -r "var_dump(phpversion('xdebug'));"
Command line code:1:
string(9) "2.9.7-dev"

下記の変更において,文字列の場合,refcountの出力が抑制されるようになったようです.
https://github.com/xdebug/xdebug/commit/dd3c9b4127778dccbf61b98746797c7b88a4caf7

リンク発見元:https://stackoverflow.com/questions/56833897/why-increasing-refcount-of-zval-not-working

これはまだよく理解できていない状態での推測なのですが,おそらく,7系でzendコンテナの実装が変更になったことによるものではないかなと思っています.

参考

Xdebugのバージョンを確認する方法
https://stackoverflow.com/questions/2479394/how-to-know-the-xdebug-version-i-have-installed

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0