Ïê˵php¾²Ì¬·½·¨¼°¾²Ì¬ÊôÐÔµÄʹÓÃ
static µÄÊôÐԺͷ½·¨£¬Ö»ÄÜ·ÃÎÊstaticµÄÊôÐԺͷ½·¨£¬²»ÄÜÀà·ÃÎʷǾ²Ì¬µÄÊôÐԺͷ½·¨¡£ÒòΪ¾²Ì¬ÊôÐԺͷ½·¨±»´´½¨Ê±£¬¿ÉÄÜ»¹Ã»ÓÐÈκÎÕâ¸öÀàµÄʵÀý¿ÉÒÔ±»µ÷Óá£
staticµÄÊôÐÔ£¬ÔÚÄÚ´æÖÐÖ»ÓÐÒ»·Ý£¬ÎªËùÓеÄʵÀý¹²Óá£
ʹÓÃself:: ¹Ø¼ü×Ö·ÃÎʵ±Ç°ÀàµÄ¾²Ì¬³ÉÔ±¡£
Ò»¸öÀàµÄËùÓÐʵÀý£¬¹²ÓÃÀàÖеľ²Ì¬ÊôÐÔ¡£
Ò²¾ÍÊÇ˵£¬ÔÚÄÚ´æÖм´Ê¹Óжà¸öʵÀý£¬¾²Ì¬µÄÊôÐÔÒ²Ö»ÓÐÒ»·Ý¡£
ÏÂÃæÀý×ÓÖеÄÉèÖÃÁËÒ»¸ö¼ÆÊýÆ÷$countÊôÐÔ£¬ÉèÖÃprivate ºÍ static ÐÞÊΡ£
<?php function testNotStaticFunc() { $n = 1; echo "Õâ¸öÊý×ÖÊÇ:{$n}"; $n++; } testNotStaticFunc(); testNotStaticFunc(); testNotStaticFunc(); testNotStaticFunc(); testNotStaticFunc(); testNotStaticFunc(); ?>
ºÜÏÔÈ»Õâ¸öº¯ÊýµÄ½á¹ûÈçÏ£º
Õâ¸öÊý×ÖÊÇ:1
Õâ¸öÊý×ÖÊÇ:1
Õâ¸öÊý×ÖÊÇ:1
Õâ¸öÊý×ÖÊÇ:1
Õâ¸öÊý×ÖÊÇ:1
Õâ¸öÊý×ÖÊÇ:1
µ«ÊÇÈç¹ûÄãµÄ³ÌÐòÊÇÕâÑù£º
<?php function testStaticFunc() { static $n = 1; echo "Õâ¸öÊý×ÖÊÇ:$n"; $n++; } testStaticFunc(); testStaticFunc(); testStaticFunc(); testStaticFunc(); testStaticFunc(); testStaticFunc(); ?>ÎÒÃÇÖ»²»¹ýÔÚ±äÁ¿Ãû¼ÓÁ˸östatic¹Ø¼ü×Ö¶øÒÑ£¬½á¹û¾Í´ó´óµÄ²»Í¬ÁË£º
Õâ¸öÊý×ÖÊÇ:1
Õâ¸öÊý×ÖÊÇ:2
Õâ¸öÊý×ÖÊÇ:3
Õâ¸öÊý×ÖÊÇ:4
Õâ¸öÊý×ÖÊÇ:5
Õâ¸öÊý×ÖÊÇ:6
¾²Ì¬ÊôÐÔÖ±½Óµ÷ÓÃ
¾²Ì¬ÊôÐÔ²»ÐèҪʵÀý»¯¾Í¿ÉÒÔÖ±½ÓʹÓã¬ÔÚÀ໹ûÓд´½¨Ê±¾Í¿ÉÒÔÖ±½ÓʹÓá£
ʹÓõķ½Ê½ÊÇ£º ÀàÃû::¾²Ì¬ÊôÐÔÃû
<?php class Math { public static $pi = 3.14; } // ÇóÒ»¸ö°ë¾¶3µÄÔ°µÄÃæ»ý¡£ $r = 3; echo "°ë¾¶ÊÇ $r µÄÃæ»ýÊÇ"; echo Math::$pi * $r * $r; echo ""; //ÕâÀïÎÒ¾õµÃ 3.14 ²»¹»¾«È·£¬ÎÒ°ÑËüÉèÖõĸü¾«È·¡£ Math::$pi = 3.141592653589793; echo "°ë¾¶ÊÇ $r µÄÃæ»ýÊÇ"; echo Math::$pi * $r * $r; ?>¾²Ì¬·½·¨
¾²Ì¬·½·¨²»ÐèÒªËùÔÚÀ౻ʵÀý»¯¾Í¿ÉÒÔÖ±½ÓʹÓá£
ʹÓõķ½Ê½ÊÇÀàÃû£º£º¾²Ì¬·½·¨Ãû
<?php class Math { public static function Max($num1, $num2) { return $num1 > $num2 ? $num1 : $num2; } } $a = 99; $b = 88; echo ¡°ÏÔʾ $a ºÍ $b ÖеÄ×î´óÖµÊÇ¡±; echo Math::Max($a, $b); ?>
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ