Hash :
7e8cd40d
Author :
Date :
2021-04-03T11:14:13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
class A {
function __call() {}
}
$a = new A();
$a->if(); // it's allowed to call a magic method with keyword since forever in PHP
class A {
function if() {} // error before 7.0, allowed now
}
$variable->foreach(); // this "foreach" is a method
$variable->method(); // this is also a method
$var->match()
foreach ($list as $value) { // this "foreach" is a keyword
}
Test::foreach(); // this is "foreach" static method
Test::method(); // this is "method" static method
// The only exception: class
$variable->class(); // this "class" should be interpreted as "keyword"
Test::class; // This "class" should still be a keyword
----------------------------------------------------
[
["keyword", "class"],
["class-name-definition", "A"],
["punctuation", "{"],
["keyword", "function"],
["function-definition", "__call"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", "{"],
["punctuation", "}"],
["punctuation", "}"],
["variable", "$a"],
["operator", "="],
["keyword", "new"],
["class-name", "A"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],
["variable", "$a"],
["operator", "->"],
["function", "if"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],
["comment", "// it's allowed to call a magic method with keyword since forever in PHP"],
["keyword", "class"],
["class-name-definition", "A"],
["punctuation", "{"],
["keyword", "function"],
["function-definition", "if"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", "{"],
["punctuation", "}"],
["comment", "// error before 7.0, allowed now"],
["punctuation", "}"],
["variable", "$variable"],
["operator", "->"],
["function", "foreach"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],
["comment", "// this \"foreach\" is a method"],
["variable", "$variable"],
["operator", "->"],
["function", "method"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],
["comment", "// this is also a method"],
["variable", "$var"],
["operator", "->"],
["function", "match"],
["punctuation", "("],
["punctuation", ")"],
["keyword", "foreach"],
["punctuation", "("],
["variable", "$list"],
["keyword", "as"],
["variable", "$value"],
["punctuation", ")"],
["punctuation", "{"],
["comment", "// this \"foreach\" is a keyword"],
["punctuation", "}"],
["class-name", "Test"],
["operator", "::"],
["function", "foreach"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],
["comment", "// this is \"foreach\" static method"],
["class-name", "Test"],
["operator", "::"],
["function", "method"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],
["comment", "// this is \"method\" static method"],
["comment", "// The only exception: class"],
["variable", "$variable"],
["operator", "->"],
["keyword", "class"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],
["comment", "// this \"class\" should be interpreted as \"keyword\""],
["class-name", "Test"],
["operator", "::"],
["keyword", "class"],
["punctuation", ";"],
["comment", "// This \"class\" should still be a keyword"]
]