debug_zval_dump( mixed $variable )
は、変数の内容をダンプする組み込み関数。変数の内容を、データ型と参照カウンタを含む、内部的な文字列表現で、出力できる。
定義
空 debug_zval_dump( 多様な型 $variable );
パラメータ
- 多様な型 $variable
内容をダンプしたい変数を指定。
戻り値
空。値を返さない。
構文
変数の内容をダンプ
debug_zval_dump( 変数 );
「変数」の内容を、データ型と参照カウンタを含む、内部的な文字列表現で、出力する。
サンプル
変数の内容をダンプ(文字列)
debug_zval_dump()、var_dump()、var_export()、print_r()を比較。
<?php
$var = "文字列";
debug_zval_dump( $var );
echo "<br />";
var_dump( $var );
echo "<br />";
var_export( $var );
echo "<br />";
print_r( $var );
?>
$var = "文字列";
debug_zval_dump( $var );
echo "<br />";
var_dump( $var );
echo "<br />";
var_export( $var );
echo "<br />";
print_r( $var );
?>
↓↓↓出力結果↓↓↓
string(9) "文字列" refcount(2)
string(9) "文字列"
'文字列'
文字列
string(9) "文字列"
'文字列'
文字列
変数の内容をダンプ(多様な型)
<?php
echo "論理型: ";
$var = TRUE;
debug_zval_dump( $var );
echo "<br />";
echo "整数型: ";
$var = 123;
debug_zval_dump( $var );
echo "<br />";
echo "浮動小数点数型: ";
$var = 1.23;
debug_zval_dump( $var );
echo "<br />";
echo "文字列型: ";
$var = "文字列";
debug_zval_dump( $var );
echo "<br />";
echo "配列型: ";
$var = array( 1, 2, 3 );
debug_zval_dump( $var );
echo "<br />";
echo "オブジェクト型: ";
class sampleClass
{
public $varTax = 0.05;
}
$var = new sampleClass();;
debug_zval_dump( $var );
echo "<br />";
echo "リソース型: ";
$var = fopen( 'sample.txt', 'r' );
debug_zval_dump( $var );
echo "<br />";
echo "NULL型: ";
$var = NULL;
debug_zval_dump( $var );
echo "<br />";
?>
echo "論理型: ";
$var = TRUE;
debug_zval_dump( $var );
echo "<br />";
echo "整数型: ";
$var = 123;
debug_zval_dump( $var );
echo "<br />";
echo "浮動小数点数型: ";
$var = 1.23;
debug_zval_dump( $var );
echo "<br />";
echo "文字列型: ";
$var = "文字列";
debug_zval_dump( $var );
echo "<br />";
echo "配列型: ";
$var = array( 1, 2, 3 );
debug_zval_dump( $var );
echo "<br />";
echo "オブジェクト型: ";
class sampleClass
{
public $varTax = 0.05;
}
$var = new sampleClass();;
debug_zval_dump( $var );
echo "<br />";
echo "リソース型: ";
$var = fopen( 'sample.txt', 'r' );
debug_zval_dump( $var );
echo "<br />";
echo "NULL型: ";
$var = NULL;
debug_zval_dump( $var );
echo "<br />";
?>
↓↓↓出力結果↓↓↓
論理型: bool(true) refcount(2)
整数型: long(123) refcount(2)
浮動小数点数型: double(1.23) refcount(2)
文字列型: string(9) “文字列” refcount(2)
配列型: array(3) refcount(2){ [0]=> long(1) refcount(1) [1]=> long(2) refcount(1) [2]=> long(3) refcount(1) }
オブジェクト型: object(sampleClass)#3 (1) refcount(2){ ["varTax"]=> double(0.05) refcount(2) }
リソース型: bool(false) refcount(2)
NULL型: NULL refcount(2)
整数型: long(123) refcount(2)
浮動小数点数型: double(1.23) refcount(2)
文字列型: string(9) “文字列” refcount(2)
配列型: array(3) refcount(2){ [0]=> long(1) refcount(1) [1]=> long(2) refcount(1) [2]=> long(3) refcount(1) }
オブジェクト型: object(sampleClass)#3 (1) refcount(2){ ["varTax"]=> double(0.05) refcount(2) }
リソース型: bool(false) refcount(2)
NULL型: NULL refcount(2)
変数の内容をダンプ(配列)
<pre>
<?php
$var = array( "レッド", "ブルー", "グリーン" );
debug_zval_dump( $var );
?>
</pre>
<?php
$var = array( "レッド", "ブルー", "グリーン" );
debug_zval_dump( $var );
?>
</pre>
↓↓↓出力結果↓↓↓
array(3) refcount(2){
[0]=>
string(9) "レッド" refcount(1)
[1]=>
string(9) "ブルー" refcount(1)
[2]=>
string(12) "グリーン" refcount(1)
}
[0]=>
string(9) "レッド" refcount(1)
[1]=>
string(9) "ブルー" refcount(1)
[2]=>
string(12) "グリーン" refcount(1)
}
変数の内容をダンプ(連想配列)
<pre>
<?php
$var = array(
"red" => "レッド",
"blue" => "ブルー",
"green" => "グリーン"
);
debug_zval_dump( $var );
?>
</pre>
<?php
$var = array(
"red" => "レッド",
"blue" => "ブルー",
"green" => "グリーン"
);
debug_zval_dump( $var );
?>
</pre>
↓↓↓出力結果↓↓↓
array(3) refcount(2){
["red"]=>
string(9) "レッド" refcount(1)
["blue"]=>
string(9) "ブルー" refcount(1)
["green"]=>
string(12) "グリーン" refcount(1)
}
["red"]=>
string(9) "レッド" refcount(1)
["blue"]=>
string(9) "ブルー" refcount(1)
["green"]=>
string(12) "グリーン" refcount(1)
}
変数の内容をダンプ(多次元配列)
<pre>
<?php
$var = array(
"red" => array(
"レッド",
"赤",
"あか",
"en" => array( "RED", "red" )
),
"blue" => array(
"ブルー",
"青",
"あお",
"en" => array( "BLUE", "blue" )
),
"green" => array(
"グリーン",
"緑",
"みどり",
"en" => array( "GREEN", "green" )
)
);
debug_zval_dump( $var );
?>
</pre>
<?php
$var = array(
"red" => array(
"レッド",
"赤",
"あか",
"en" => array( "RED", "red" )
),
"blue" => array(
"ブルー",
"青",
"あお",
"en" => array( "BLUE", "blue" )
),
"green" => array(
"グリーン",
"緑",
"みどり",
"en" => array( "GREEN", "green" )
)
);
debug_zval_dump( $var );
?>
</pre>
↓↓↓出力結果↓↓↓
array(3) refcount(2){
["red"]=>
array(4) refcount(1){
[0]=>
string(9) "レッド" refcount(1)
[1]=>
string(3) "赤" refcount(1)
[2]=>
string(6) "あか" refcount(1)
["en"]=>
array(2) refcount(1){
[0]=>
string(3) "RED" refcount(1)
[1]=>
string(3) "red" refcount(1)
}
}
["blue"]=>
array(4) refcount(1){
[0]=>
string(9) "ブルー" refcount(1)
[1]=>
string(3) "青" refcount(1)
[2]=>
string(6) "あお" refcount(1)
["en"]=>
array(2) refcount(1){
[0]=>
string(4) "BLUE" refcount(1)
[1]=>
string(4) "blue" refcount(1)
}
}
["green"]=>
array(4) refcount(1){
[0]=>
string(12) "グリーン" refcount(1)
[1]=>
string(3) "緑" refcount(1)
[2]=>
string(9) "みどり" refcount(1)
["en"]=>
array(2) refcount(1){
[0]=>
string(5) "GREEN" refcount(1)
[1]=>
string(5) "green" refcount(1)
}
}
}
["red"]=>
array(4) refcount(1){
[0]=>
string(9) "レッド" refcount(1)
[1]=>
string(3) "赤" refcount(1)
[2]=>
string(6) "あか" refcount(1)
["en"]=>
array(2) refcount(1){
[0]=>
string(3) "RED" refcount(1)
[1]=>
string(3) "red" refcount(1)
}
}
["blue"]=>
array(4) refcount(1){
[0]=>
string(9) "ブルー" refcount(1)
[1]=>
string(3) "青" refcount(1)
[2]=>
string(6) "あお" refcount(1)
["en"]=>
array(2) refcount(1){
[0]=>
string(4) "BLUE" refcount(1)
[1]=>
string(4) "blue" refcount(1)
}
}
["green"]=>
array(4) refcount(1){
[0]=>
string(12) "グリーン" refcount(1)
[1]=>
string(3) "緑" refcount(1)
[2]=>
string(9) "みどり" refcount(1)
["en"]=>
array(2) refcount(1){
[0]=>
string(5) "GREEN" refcount(1)
[1]=>
string(5) "green" refcount(1)
}
}
}
変数の内容をダンプ(オブジェクト)
<pre>
<?php
class taxClass
{
public $varTax = 0.05;
function func_tax( $var ) {
return $var * ( 1 + $this->varTax );
}
}
$var_class = new taxClass();
debug_zval_dump( $var_class );
?>
</pre>
<?php
class taxClass
{
public $varTax = 0.05;
function func_tax( $var ) {
return $var * ( 1 + $this->varTax );
}
}
$var_class = new taxClass();
debug_zval_dump( $var_class );
?>
</pre>
↓↓↓出力結果↓↓↓
object(taxClass)#3 (1) refcount(2){
["varTax"]=>
double(0.05) refcount(2)
}
["varTax"]=>
double(0.05) refcount(2)
}