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-- 49Same variable used as static and non static. 50--------- 510 5210 53--------- 540 5511 56--------- 570 5812 59 60Lots of initialisations in the same statement. 61------------- Call 0 -------------- 62Unitialised : 63Initialised to 10: 10 64Initialised to 20: 20 65Unitialised : 66Initialised to 30: 30 67------------- Call 1 -------------- 68Unitialised : 1 69Initialised to 10: 11 70Initialised to 20: 21 71Unitialised : 1 72Initialised to 30: 31 73------------- Call 2 -------------- 74Unitialised : 2 75Initialised to 10: 12 76Initialised to 20: 22 77Unitialised : 2 78Initialised to 30: 32 79 80Using static keyword at global scope 81 10 821 11 832 12 84