Results of 1 - 1 of about 1 for noref (0.001 sec.)
- 変数のスコープ | PHP 8.3 9414
- 変数のスコープ 変数のスコープは、その変数が定義されたコンテキストです。 PHP には関数スコープとグローバルスコープがあります。 関数の外部で定義されたあらゆる変数は、グローバルスコープになります。 ファイルが include された場合、 そのファイルに
... があります。 <?php function test_global_ref () { global $obj ; $new = new stdClass ; $obj = & $new ; } function test_global_noref () { global $obj ; $new = new stdClass ; $obj = $new ; } test_global_ref (); var_dump ( $obj ); test_global_noref (); var_ ... sset( $obj -> property )) { $obj -> property = 1 ; } else { $obj -> property ++; } return $obj ; } function & get_instance_noref () { static $obj ; echo 'Static object: ' ; var_dump ( $obj ); if (!isset( $obj )) { $new = new stdClass ; // Assign the o ... rty ++; } return $obj ; } $obj1 = get_instance_ref (); $still_obj1 = get_instance_ref (); echo "\n" ; $obj2 = get_instance_noref (); $still_obj2 = get_instance_noref (); 上の例の出力は以下となります。 Static object: NULL Static object: NULL Static obj ...
-
https://man.mtool.work/php/8.3/language.variables.scope.html
PREV
1
NEXT