note 128390 added to language.oop5.static

From: Date: Thu, 13 Apr 2023 06:49:57 +0000
Subject: note 128390 added to language.oop5.static
Groups: php.notes 
Request: Send a blank email to php-notes+get-220347@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/128390 Del: integrated -- https://main.php.net/note/delete/128390/integrated Del: useless -- https://main.php.net/note/delete/128390/useless Del: bad code -- https://main.php.net/note/delete/128390/bad+code Del: spam -- https://main.php.net/note/delete/128390/spam Del: non-english -- https://main.php.net/note/delete/128390/non-english Del: in docs -- https://main.php.net/note/delete/128390/in+docs Del: other reasons-- https://main.php.net/note/delete/128390 Reject -- https://main.php.net/note/reject/128390 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220347) next »