note 118097 added to language.oop5.static

From: Date: Fri, 02 Oct 2015 19:44:07 +0000
Subject: note 118097 added to language.oop5.static
Groups: php.notes 
Request: Send a blank email to php-notes+get-203898@lists.php.net to get a copy of this message
The static keyword can still be used (in a non-oop way) inside a function. So if you need a value stored with your class, but it is very function specific, you can use this: class aclass { public static function b(){ static $d=12; // Set to 12 on first function call only $d+=12; return "$d\n"; } } echo aclass::b(); //24 echo aclass::b(); //36 echo aclass::b(); //48 echo aclass::$d; //fatal error ---- Server IP: 72.52.91.14 Probable Submitter: 86.162.65.80 ---- Manual Page -- http://php.net/manual/en/language.oop5.static.php Edit -- https://master.php.net/note/edit/118097 Del: integrated -- https://master.php.net/note/delete/118097/integrated Del: useless -- https://master.php.net/note/delete/118097/useless Del: bad code -- https://master.php.net/note/delete/118097/bad+code Del: spam -- https://master.php.net/note/delete/118097/spam Del: non-english -- https://master.php.net/note/delete/118097/non-english Del: in docs -- https://master.php.net/note/delete/118097/in+docs Del: other reasons-- https://master.php.net/note/delete/118097 Reject -- https://master.php.net/note/reject/118097 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#203898) next »