note 128391 added to language.oop5.static

From: Date: Thu, 13 Apr 2023 06:50:14 +0000
Subject: note 128391 added to language.oop5.static
Groups: php.notes 
Request: Send a blank email to php-notes+get-220346@lists.php.net to get a copy of this message
<?php /** * USE @static KEYWORD IN A FUNCTION * when you use the keyword @static in the declaration of a variable, * this variable's value will not be DELETED from the memory scope * after the function call is ended. */ // example without static function &foo() { $var = 0; $var ++; return $var; } $x = &foo(); foo(); foo(); foo(); foo(); echo "This is x without static: $x </br>"; // output : This is x without static: 1 // same example with static function &foo_with_static() { static $var = 0; $var ++; return $var; } $x = &foo_with_static(); foo_with_static(); foo_with_static(); foo_with_static(); foo_with_static(); echo "This is x with static: $x"; // output : This is x with static: 5 ?> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.130 (proxied: 102.155.132.222) ---- Manual Page -- https://php.net/manual/en/language.oop5.static.php Edit -- https://main.php.net/note/edit/128391 Del: integrated -- https://main.php.net/note/delete/128391/integrated Del: useless -- https://main.php.net/note/delete/128391/useless Del: bad code -- https://main.php.net/note/delete/128391/bad+code Del: spam -- https://main.php.net/note/delete/128391/spam Del: non-english -- https://main.php.net/note/delete/128391/non-english Del: in docs -- https://main.php.net/note/delete/128391/in+docs Del: other reasons-- https://main.php.net/note/delete/128391 Reject -- https://main.php.net/note/reject/128391 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220346) next »