xref: /php-src/tests/lang/static_basic_001.phpt (revision 462da6e0)
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 "Uninitialized    : $a\n";
25    echo "Initialized to 10: $b\n";
26    echo "Initialized to 20: $c\n";
27    echo "Uninitialized    : $d\n";
28    echo "Initialized 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 --------------
62Uninitialized    :
63Initialized to 10: 10
64Initialized to 20: 20
65Uninitialized    :
66Initialized to 30: 30
67------------- Call 1 --------------
68Uninitialized    : 1
69Initialized to 10: 11
70Initialized to 20: 21
71Uninitialized    : 1
72Initialized to 30: 31
73------------- Call 2 --------------
74Uninitialized    : 2
75Initialized to 10: 12
76Initialized to 20: 22
77Uninitialized    : 2
78Initialized to 30: 32
79
80Using static keyword at global scope
81 10
821 11
832 12
84