1--TEST-- 2Static keyword - basic tests 3--FILE-- 4<?php 5 6echo "\nSame variable used as static and non static.\n"; 7function staticNonStatic() { 8 echo "---------\n"; 9 $a=0; 10 echo "$a\n"; 11 static $a=10; 12 echo "$a\n"; 13 $a++; 14} 15staticNonStatic(); 16staticNonStatic(); 17staticNonStatic(); 18 19echo "\nLots of initialisations in the same statement.\n"; 20function manyInits() { 21 static $counter=0; 22 echo "------------- Call $counter --------------\n"; 23 static $a, $b=10, $c=20, $d, $e=30; 24 echo "Unitialised : $a\n"; 25 echo "Initialised to 10: $b\n"; 26 echo "Initialised to 20: $c\n"; 27 echo "Unitialised : $d\n"; 28 echo "Initialised to 30: $e\n"; 29 $a++; 30 $b++; 31 $c++; 32 $d++; 33 $e++; 34 $counter++; 35} 36manyInits(); 37manyInits(); 38manyInits(); 39 40echo "\nUsing static keyword at global scope\n"; 41for ($i=0; $i<3; $i++) { 42 static $s, $k=10; 43 echo "$s $k\n"; 44 $s++; 45 $k++; 46} 47?> 48--EXPECT-- 49 50Same variable used as static and non static. 51--------- 520 5310 54--------- 550 5611 57--------- 580 5912 60 61Lots of initialisations in the same statement. 62------------- Call 0 -------------- 63Unitialised : 64Initialised to 10: 10 65Initialised to 20: 20 66Unitialised : 67Initialised to 30: 30 68------------- Call 1 -------------- 69Unitialised : 1 70Initialised to 10: 11 71Initialised to 20: 21 72Unitialised : 1 73Initialised to 30: 31 74------------- Call 2 -------------- 75Unitialised : 2 76Initialised to 10: 12 77Initialised to 20: 22 78Unitialised : 2 79Initialised to 30: 32 80 81Using static keyword at global scope 82 10 831 11 842 12 85