pull/1/head
韩天峰 8 months ago
parent f3565a6439
commit 2b9417d78f
  1. 23
      src/Php/Translator.php
  2. 356
      tests/core/lang/023-1.inc
  3. 6
      tests/core/lang/023-2.inc
  4. 11625
      tests/core/lang/024.phpt
  5. 532
      tests/core/lang/025.phpt
  6. 6
      tests/core/lang/026.phpt
  7. 12
      tests/core/lang/027.phpt
  8. 1059
      tests/core/lang/028.phpt
  9. 40
      tests/core/lang/030.phpt
  10. 37
      tests/core/lang/032.phpt
  11. 44
      tests/core/lang/033.phpt
  12. 19
      tests/core/lang/034.phpt
  13. 36
      tests/core/lang/035.phpt
  14. 29
      tests/core/lang/036.phpt
  15. 32
      tests/core/lang/037.phpt
  16. 40
      tests/core/lang/038.phpt
  17. 45
      tests/core/lang/039.phpt
  18. 13
      tests/core/lang/040.phpt
  19. 25
      tests/core/lang/041.phpt
  20. 24
      tests/core/lang/042.phpt
  21. 24
      tests/core/lang/043.phpt
  22. 26
      tests/core/lang/044.phpt
  23. 26
      tests/core/lang/045.phpt
  24. 13
      tests/core/lang/array_shortcut_001.phpt
  25. 13
      tests/core/lang/array_shortcut_002.phpt
  26. 13
      tests/core/lang/array_shortcut_003.phpt
  27. 20
      tests/core/lang/array_shortcut_005.phpt
  28. 11
      tests/core/lang/bison1.phpt
  29. 20
      tests/core/lang/bug18872.phpt
  30. 12
      tests/core/lang/bug19566.phpt
  31. 35
      tests/core/lang/bug7515.phpt

@ -659,20 +659,21 @@ class Translator extends \PhpAot\Core\Translator
$items = $node->items;
// 优化代码风格,空数组直接返回{},否则会产生一些空洞内容
if (count($items) === 0) {
return '{}';
return self::TYPE_ARRAY .'{}';
}
$list = [];
$this->indentLevel++;
foreach ($items as $item) {
if ($item->key) {
$list[] = $this->getIndent() . '{ ' . $this->parseIdentifier($item->key) . ', php::Variant(' . $this->parseIdentifier($item->value) . ') }';
$list[] = $this->getIndent() . '{ ' . $this->parseIdentifier($item->key) . ', ' .
self::TYPE_VAR . '(' . $this->parseIdentifier($item->value) . ') }';
} else {
$value = $this->parseIdentifier($item->value);
$list[] = $this->getIndent() . 'php::Variant(' . $value . ')';
$list[] = $this->getIndent() . self::TYPE_VAR . '(' . $value . ')';
}
}
$this->indentLevel--;
return '{' . PHP_EOL .
return self::TYPE_ARRAY . '{' . PHP_EOL .
implode(', ' . PHP_EOL, $list) . PHP_EOL .
$this->getIndent() .
'}';
@ -1202,9 +1203,7 @@ class Translator extends \PhpAot\Core\Translator
private function escapeString($str): string
{
$search = ["\n", "\r", "\t", "\""];
$replace = ['\n', '\r', '\t', '\"'];
return str_replace($search, $replace, $str);
return addcslashes($str, "\\\"\n\r\t\v\f\0\x01..\x1f\x7f..\xff");
}
private function parseInterpolatedStringPart(Node $expr): string
@ -1320,8 +1319,18 @@ class Translator extends \PhpAot\Core\Translator
$code .= $this->getIndent() . self::TYPE_VAR . ' ' . $keyVar . ' = iter.key();' . PHP_EOL;
$this->addVar($keyVar, self::TYPE_VAR);
}
if ($node->valueVar->getType() == 'Expr_ArrayDimFetch') {
$array = $this->parseIdentifier($node->valueVar->var);
if (!$this->hasVar($array) or $node->valueVar->dim === null) {
abort($node->valueVar);
}
$dim = $this->parseIdentifier($node->valueVar->dim);
$code .= $this->getIndent() . "$array.offsetSet($dim, iter.value());";
} else {
$code .= $this->getIndent() . self::TYPE_VAR . ' ' . $valueVar . ' = iter.value();' . PHP_EOL;
$this->addVar($valueVar, self::TYPE_VAR);
}
$code .= $this->parseStmts($stmts);
$this->indentLevel--;

@ -0,0 +1,356 @@
<html>
<head>
<?php
/* the point of this file is to intensively test various aspects of
* the parser. right now, each test focuses in one aspect only
* (e.g. variable aliasing, arithmetic operator, various control
* structures), while trying to combine code from other parts of the
* parser as well.
*/
?>
*** Testing assignments and variable aliasing: ***<br>
<?php
/* This test tests assignments to variables using other variables as variable-names */
$a = "b";
$$a = "test";
$$$a = "blah";
${$$$a}["associative arrays work too"] = "this is nifty";
?>
This should read "blah": <?php echo "$test<br>\n"; ?>
This should read "this is nifty": <?php echo $blah[$test="associative arrays work too"]."<br>\n"; ?>
*************************************************<br>
*** Testing integer operators ***<br>
<?php
/* test just about any operator possible on $i and $j (ints) */
$i = 5;
$j = 3;
?>
Correct result - 8: <?php echo $i+$j; ?><br>
Correct result - 8: <?php echo $i+$j; ?><br>
Correct result - 2: <?php echo $i-$j; ?><br>
Correct result - -2: <?php echo $j-$i; ?><br>
Correct result - 15: <?php echo $i*$j; ?><br>
Correct result - 15: <?php echo $j*$i; ?><br>
Correct result - 2: <?php echo $i%$j; ?><br>
Correct result - 3: <?php echo $j%$i; ?><br>
*********************************<br>
*** Testing real operators ***<br>
<?php
/* test just about any operator possible on $i and $j (floats) */
$i = 5.0;
$j = 3.0;
?>
Correct result - 8: <?php echo $i+$j; ?><br>
Correct result - 8: <?php echo $i+$j; ?><br>
Correct result - 2: <?php echo $i-$j; ?><br>
Correct result - -2: <?php echo $j-$i; ?><br>
Correct result - 15: <?php echo $i*$j; ?><br>
Correct result - 15: <?php echo $j*$i; ?><br>
Correct result - 2: <?php echo $i%$j; ?><br>
Correct result - 3: <?php echo $j%$i; ?><br>
*********************************<br>
*** Testing if/elseif/else control ***<br>
<?php
/* sick if/elseif/else test by Andi :) */
$a = 5;
if ($a == "4") {
echo "This "." does "." not "." work<br>\n";
} elseif ($a == "5") {
echo "This "." works<br>\n";
$a = 6;
if ("andi" == ($test = "andi")) {
echo "this_still_works<br>\n";
} elseif (1) {
echo "should_not_print<br>\n";
} else {
echo "should_not_print<br>\n";
}
if (44 == 43) {
echo "should_not_print<br>\n";
} else {
echo "should_print<br>\n";
}
} elseif ($a == 6) {
echo "this "."broken<br>\n";
if (0) {
echo "this_should_not_print<br>\n";
} else {
echo "TestingDanglingElse_This_Should_not_print<br>\n";
}
} else {
echo "This "."does "." not"." work<br>\n";
}
?>
*** Seriously nested if's test ***<br>
** spelling correction by kluzz **
<?php
/* yet another sick if/elseif/else test by Zeev */
$i=$j=0;
echo "Only two lines of text should follow:<br>\n";
if (0) { /* this code is not supposed to be executed */
echo "hmm, this shouldn't be displayed #1<br>\n";
$j++;
if (1) {
$i
+=
$j;
if (0) {
$j = ++$i;
if (1) {
$j *= $i;
echo "damn, this shouldn't be displayed<br>\n";
} else {
$j /= $i;
++$j;
echo "this shouldn't be displayed either<br>\n";
}
} elseif (1) {
$i++; $j++;
echo "this isn't supposed to be displayed<br>\n";
}
} elseif (0) {
$i++;
echo "this definitely shouldn't be displayed<br>\n";
} else {
--$j;
echo "and this too shouldn't be displayed<br>\n";
while ($j>0) {
$j--;
}
}
} elseif (2-2) { /* as long as 2-2==0, this isn't supposed to be executed either */
$i = ++$j;
echo "hmm, this shouldn't be displayed #2<br>\n";
if (1) {
$j = ++$i;
if (0) {
$j = $i*2+$j*($i++);
if (1) {
$i++;
echo "damn, this shouldn't be displayed<br>\n";
} else {
$j++;
echo "this shouldn't be displayed either<br>\n";
}
} else if (1) {
++$j;
echo "this isn't supposed to be displayed<br>\n";
}
} elseif (0) {
$j++;
echo "this definitely shouldn't be displayed<br>\n";
} else {
$i++;
echo "and this too shouldn't be displayed<br>\n";
}
} else {
$j=$i++; /* this should set $i to 1, but shouldn't change $j (it's assigned $i's previous values, zero) */
echo "this should be displayed. should be: \$i=1, \$j=0. is: \$i=$i, \$j=$j<br>\n";
if (1) {
$j += ++$i; /* ++$i --> $i==2, $j += 2 --> $j==2 */
if (0) {
$j += 40;
if (1) {
$i += 50;
echo "damn, this shouldn't be displayed<br>\n";
} else {
$j += 20;
echo "this shouldn't be displayed either<br>\n";
}
} else if (1) {
$j *= $i; /* $j *= 2 --> $j == 4 */
echo "this is supposed to be displayed. should be: \$i=2, \$j=4. is: \$i=$i, \$j=$j<br>\n";
echo "3 loop iterations should follow:<br>\n";
while ($i<=$j) {
echo $i++." $j<br>\n";
}
}
} elseif (0) {
echo "this definitely shouldn't be displayed<br>\n";
} else {
echo "and this too shouldn't be displayed<br>\n";
}
echo "**********************************<br>\n";
}
?>
*** C-style else-if's ***<br>
<?php
/* looks like without we even tried, C-style else-if structure works fine! */
if ($a=0) {
echo "This shouldn't be displayed<br>\n";
} else if ($a++) {
echo "This shouldn't be displayed either<br>\n";
} else if (--$a) {
echo "No, this neither<br>\n";
} else if (++$a) {
echo "This should be displayed<br>\n";
} else {
echo "This shouldn't be displayed at all<br>\n";
}
?>
*************************<br>
*** WHILE tests ***<br>
<?php
$i=0;
$j=20;
while ($i<(2*$j)) {
if ($i>$j) {
echo "$i is greater than $j<br>\n";
} else if ($i==$j) {
echo "$i equals $j<br>\n";
} else {
echo "$i is smaller than $j<br>\n";
}
$i++;
}
?>
*******************<br>
*** Nested WHILEs ***<br>
<?php
$arr_len=3;
$i=0;
while ($i<$arr_len) {
$j=0;
while ($j<$arr_len) {
$k=0;
while ($k<$arr_len) {
${"test$i$j"}[$k] = $i+$j+$k;
$k++;
}
$j++;
}
$i++;
}
echo "Each array variable should be equal to the sum of its indices:<br>\n";
$i=0;
while ($i<$arr_len) {
$j=0;
while ($j<$arr_len) {
$k=0;
while ($k<$arr_len) {
echo "\${test$i$j}[$k] = ".${"test$i$j"}[$k]."<br>\n";
$k++;
}
$j++;
}
$i++;
}
?>
*********************<br>
*** hash test... ***<br>
<?php
/*
$i=0;
while ($i<10000) {
$arr[$i]=$i;
$i++;
}
$i=0;
while ($i<10000) {
echo $arr[$i++]."<br>\n";
}
*/
echo "commented out...";
?>
**************************<br>
*** Hash resizing test ***<br>
<?php
$i = 10;
$a = 'b';
while ($i > 0) {
$a = $a . 'a';
echo "$a<br>\n";
$resize[$a] = $i;
$i--;
}
$i = 10;
$a = 'b';
while ($i > 0) {
$a = $a . 'a';
echo "$a<br>\n";
echo $resize[$a]."<br>\n";
$i--;
}
?>
**************************<br>
*** break/continue test ***<br>
<?php
$i=0;
echo "\$i should go from 0 to 2<br>\n";
while ($i<5) {
if ($i>2) {
break;
}
$j=0;
echo "\$j should go from 3 to 4, and \$q should go from 3 to 4<br>\n";
while ($j<5) {
if ($j<=2) {
$j++;
continue;
}
echo " \$j=$j<br>\n";
for ($q=0; $q<=10; $q++) {
if ($q<3) {
continue;
}
if ($q>4) {
break;
}
echo " \$q=$q<br>\n";
}
$j++;
}
$j=0;
echo "\$j should go from 0 to 2<br>\n";
while ($j<5) {
if ($j>2) {
$k=0;
echo "\$k should go from 0 to 2<br>\n";
while ($k<5) {
if ($k>2) {
break 2;
}
echo " \$k=$k<br>\n";
$k++;
}
}
echo " \$j=$j<br>\n";
$j++;
}
echo "\$i=$i<br>\n";
$i++;
}
?>
***********************<br>
*** Nested file include test ***<br>
<?php include("023-2.inc"); ?>
********************************<br>
<?php
{
echo "Tests completed.<br>\n"; # testing some PHP style comment...
}
?>

@ -0,0 +1,6 @@
<html>
This is Finish.phtml. This file is supposed to be included
from regression_test.phtml. This is normal HTML.
<?php echo "and this is PHP code, 2+2=".(2+2).""; ?>
</html>

File diff suppressed because it is too large Load Diff

@ -0,0 +1,532 @@
--TEST--
Mean recursion test
--FILE--
<?php
function RekTest ($nr) {
echo " $nr ";
$j=$nr+1;
while ($j < 10) {
echo " a ";
RekTest($j);
$j++;
echo " b $j ";
}
echo "\n";
}
function main() {
RekTest(0);
}
?>
--EXPECT--
0 a 1 a 2 a 3 a 4 a 5 a 6 a 7 a 8 a 9
b 10
b 9 a 9
b 10
b 8 a 8 a 9
b 10
b 9 a 9
b 10
b 7 a 7 a 8 a 9
b 10
b 9 a 9
b 10
b 8 a 8 a 9
b 10
b 9 a 9
b 10
b 6 a 6 a 7 a 8 a 9
b 10
b 9 a 9
b 10
b 8 a 8 a 9
b 10
b 9 a 9
b 10
b 7 a 7 a 8 a 9
b 10
b 9 a 9
b 10
b 8 a 8 a 9
b 10
b 9 a 9
b 10
b 5 a 5 a 6 a 7 a 8 a 9
b 10
b 9 a 9
b 10
b 8 a 8 a 9
b 10
b 9 a 9
b 10
b 7 a 7 a 8 a 9
b 10
b 9 a 9
b 10
b 8 a 8 a 9
b 10
b 9 a 9
b 10
b 6 a 6 a 7 a 8 a 9
b 10
b 9 a 9
b 10
b 8 a 8 a 9
b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 9
b 10
b 7 a 7 a 8 a 9
b 10
b 9 a 9
b 10
b 8 a 8 a 9
b 10
b 9 a 9
b 10
b 4 a 4 a 5 a 6 a 7 a 8 a 9
b 10
b 9 a 9
b 10
b 8 a 8 a 9
b 10
b 9 a 9
b 10
b 7 a 7 a 8 a 9
b 10
b 9 a 9
b 10
b 8 a 8 a 9
b 10
b 9 a 9
b 10
b 6 a 6 a 7 a 8 a 9
b 10
b 9 a 9
b 10
b 8 a 8 a 9
b 10
b 9 a 9
b 10
b 7 a 7 a 8 a 9
b 10
b 9 a 9
b 10
b 8 a 8 a 9
b 10
b 9 a 9
b 10
b 5 a 5 a 6 a 7 a 8 a 9
b 10
b 9 a 9
b 10
b 8 a 8 a 9
b 10
b 9 a 9
b 10
b 7 a 7 a 8 a 9
b 10
b 9 a 9
b 10
b 8 a 8 a 9
b 10
b 9 a 9
b 10
b 6 a 6 a 7 a 8 a 9
b 10
b 9 a 9
b 10
b 8 a 8 a 9
b 10
b 9 a 9
b 10
b 7 a 7 a 8 a 9
b 10
b 9 a 9
b 10
b 8 a 8 a 9
b 10
b 9 a 9
b 10

@ -0,0 +1,6 @@
--TEST--
Testing string scanner conformance
--FILE--
<?php echo "\"\t\\'" . '\n\\\'a\\\b\\'; ?>
--EXPECT--
" \'\n\'a\\b\

@ -0,0 +1,12 @@
--TEST--
Testing do-while loop
--FILE--
<?php
$i=3;
do {
echo $i;
$i--;
} while($i>0);
?>
--EXPECT--
321

File diff suppressed because it is too large Load Diff

@ -0,0 +1,40 @@
--TEST--
$this in constructor test
--SKIPIF--
<?php die("skip");?>
--FILE--
<?php
class foo {
public $Name;
function __construct($name) {
$GLOBALS['List']= &$this;
$this->Name = $name;
$GLOBALS['List']->echoName();
}
function echoName() {
$GLOBALS['names'][]=$this->Name;
}
}
function &foo2(&$foo) {
return $foo;
}
$bar1 =new foo('constructor');
$bar1->Name = 'outside';
$bar1->echoName();
$List->echoName();
$foo = new foo('constructor');
$bar1 =& foo2($foo);
$bar1->Name = 'outside';
$bar1->echoName();
$List->echoName();
print ($names==array('constructor','outside','outside','constructor','outside','outside')) ? 'success':'failure';
?>
--EXPECT--
success

@ -0,0 +1,37 @@
--TEST--
Class method registration
--SKIPIF--
<?php die("skip");?>
--FILE--
<?php
class A {
function foo() {}
}
class B extends A {
function foo() {}
}
class C extends B {
function foo() {}
}
class D extends A {
}
class F extends D {
function foo() {}
}
// Following class definition should fail, but cannot test
/*
class X {
function foo() {}
function foo() {}
}
*/
echo "OK\n";
?>
--EXPECT--
OK

@ -0,0 +1,44 @@
--TEST--
Alternative syntaxes test
--FILE--
<?php
$a = 1;
echo "If: ";
if ($a) echo 1; else echo 0;
if ($a):
echo 1;
else:
echo 0;
endif;
echo "\nWhile: ";
while ($a<5) echo $a++;
while ($a<9):
echo ++$a;
endwhile;
echo "\nFor: ";
for($a=0;$a<5;$a++) echo $a;
for($a=0;$a<5;$a++):
echo $a;
endfor;
echo "\nSwitch: ";
switch ($a):
case 0;
echo 0;
break;
case 5:
echo 1;
break;
default;
echo 0;
break;
endswitch;
?>
--EXPECT--
If: 11
While: 12346789
For: 0123401234
Switch: 1

@ -0,0 +1,19 @@
--TEST--
Bug #12647 (Locale settings affecting float parsing)
--INI--
precision=14
--SKIPIF--
<?php # try to activate a german locale
if (setlocale(LC_NUMERIC, "de_DE.UTF-8", "de_DE", "de", "german", "ge", "de_DE.ISO-8859-1") === FALSE) {
print "skip Can't find german locale";
}
?>
--FILE--
<?php
# activate the german locale
setlocale(LC_NUMERIC, "de_DE.UTF-8", "de_DE", "de", "german", "ge", "de_DE.ISO-8859-1");
echo (float)"3.14", "\n";
?>
--EXPECT--
3.14

@ -0,0 +1,36 @@
--TEST--
ZE2: set_exception_handler()
--SKIPIF--
<?php die("skip");?>
--FILE--
<?php
class MyException extends Exception {
function __construct(public $error) {}
function getException()
{
return $this->error;
}
}
function ThrowException()
{
throw new MyException("'This is an exception!'");
}
try {
} catch (MyException $exception) {
print "There shouldn't be an exception: " . $exception->getException();
print "\n";
}
try {
ThrowException();
} catch (MyException $exception) {
print "There was an exception: " . $exception->getException();
print "\n";
}
?>
--EXPECT--
There was an exception: 'This is an exception!'

@ -0,0 +1,29 @@
--TEST--
Child public element should not override parent private element in parent methods
--SKIPIF--
<?php die("skip");?>
--FILE--
<?php
class par {
private $id = "foo";
function displayMe()
{
print $this->id;
}
};
class chld extends par {
public $id = "bar";
function displayHim()
{
parent::displayMe();
}
};
$obj = new chld();
$obj->displayHim();
?>
--EXPECT--
foo

@ -0,0 +1,32 @@
--TEST--
'Static' binding for private variables
--SKIPIF--
<?php die("skip");?>
--FILE--
<?php
class par {
private $id="foo";
function displayMe()
{
$this->displayChild();
}
};
class chld extends par {
private $id = "bar";
function displayChild()
{
print $this->id;
}
};
$obj = new chld();
$obj->displayMe();
?>
--EXPECT--
bar

@ -0,0 +1,40 @@
--TEST--
Convert warnings to exceptions
--SKIPIF--
<?php die("skip");?>
--FILE--
<?php
class MyException extends Exception
{
function __construct($errstr, $errno=0, $errfile='', $errline=0)
{
parent::__construct($errstr, $errno);
$this->file = $errfile;
$this->line = $errline;
}
}
function Error2Exception($errno, $errstr, $errfile, $errline)
{
throw new MyException($errstr, $errno);//, $errfile, $errline);
}
$err_msg = 'no exception';
set_error_handler('Error2Exception');
try
{
$con = fopen("/tmp/a_file_that_does_not_exist",'r');
}
catch (Exception $e)
{
$trace = $e->getTrace();
var_dump($trace[0]['function']);
var_dump($trace[1]['function']);
}
?>
--EXPECT--
string(15) "Error2Exception"
string(5) "fopen"

@ -0,0 +1,45 @@
--TEST--
Catch Interfaces
--SKIPIF--
<?php die("skip");?>
--FILE--
<?php
interface Catchable
{
}
class MyException extends Exception implements Catchable
{
function __construct($errstr, $errno, $errfile, $errline)
{
parent::__construct($errstr, $errno);
$this->file = $errfile;
$this->line = $errline;
}
}
function Error2Exception($errno, $errstr, $errfile, $errline)
{
throw new MyException($errstr, $errno, $errfile, $errline);
}
$err_msg = 'no exception';
set_error_handler('Error2Exception');
try
{
$con = fopen('/tmp/a_file_that_does_not_exist','r');
}
catch (Catchable $e)
{
echo "Catchable\n";
}
catch (Exception $e)
{
echo "Exception\n";
}
?>
--EXPECT--
Catchable

@ -0,0 +1,13 @@
--TEST--
foreach into array
--FILE--
<?php
$a = array(0,1);
$b[0]=2;
foreach($a as $b[0]) {
echo $b[0]."\n";
}
?>
--EXPECT--
0
1

@ -0,0 +1,25 @@
--TEST--
Dynamic access of static members
--SKIPIF--
<?php die("skip");?>
--FILE--
<?php
class A {
public static $b = 'foo';
}
$classname = 'A';
$wrongClassname = 'B';
echo $classname::$b."\n";
echo $wrongClassname::$b."\n";
?>
===DONE===
--EXPECTF--
foo
Fatal error: Uncaught Error: Class "B" not found in %s:%d
Stack trace:
#0 {main}
thrown in %s041.php on line %d

@ -0,0 +1,24 @@
--TEST--
Dynamic access of constants
--SKIPIF--
<?php die("skip");?>
--FILE--
<?php
class A {
const B = 'foo';
}
$classname = 'A';
$wrongClassname = 'B';
echo $classname::B."\n";
echo $wrongClassname::B."\n";
?>
===DONE===
--EXPECTF--
foo
Fatal error: Uncaught Error: Class "B" not found in %s:%d
Stack trace:
#0 {main}
thrown in %s042.php on line %d

@ -0,0 +1,24 @@
--TEST--
Dynamic call for static methods
--SKIPIF--
<?php die("skip");?>
--FILE--
<?php
class A {
static function foo() { return 'foo'; }
}
$classname = 'A';
$wrongClassname = 'B';
echo $classname::foo()."\n";
echo $wrongClassname::foo()."\n";
?>
===DONE===
--EXPECTF--
foo
Fatal error: Uncaught Error: Class "B" not found in %s:%d
Stack trace:
#0 {main}
thrown in %s043.php on line %d

@ -0,0 +1,26 @@
--TEST--
Dynamic call for static methods dynamically named
--SKIPIF--
<?php die("skip");?>
--FILE--
<?php
class A {
static function foo() { return 'foo'; }
}
$classname = 'A';
$wrongClassname = 'B';
$methodname = 'foo';
echo $classname::$methodname()."\n";
echo $wrongClassname::$methodname()."\n";
?>
===DONE===
--EXPECTF--
foo
Fatal error: Uncaught Error: Class "B" not found in %s:%d
Stack trace:
#0 {main}
thrown in %s044.php on line %d

@ -0,0 +1,26 @@
--TEST--
Timeout again inside register_shutdown_function
--SKIPIF--
<?php
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
if (PHP_ZTS) die("skip hard_timeout works only on no-zts builds");
?>
--INI--
hard_timeout=1
--FILE--
<?php
function plop() {
while (true);
}
function main() {
set_time_limit(1);
register_shutdown_function("plop");
plop();
}
?>
===DONE===
--EXPECTF--
Fatal error: Maximum execution time of 1 second exceeded in %s on line %d
Fatal error: Maximum execution time of 1 second exceeded in %s on line %d

@ -0,0 +1,13 @@
--TEST--
Square bracket array shortcut test
--FILE--
<?php
print_r([1, 2, 3]);
?>
--EXPECT--
Array
(
[0] => 1
[1] => 2
[2] => 3
)

@ -0,0 +1,13 @@
--TEST--
Square bracket associative array shortcut test
--FILE--
<?php
print_r(["foo" => "orange", "bar" => "apple", "baz" => "lemon"]);
?>
--EXPECT--
Array
(
[foo] => orange
[bar] => apple
[baz] => lemon
)

@ -0,0 +1,13 @@
--TEST--
Testing array shortcut and bracket operator
--FILE--
<?php
$a = [1, 2, 3, 4, 5];
print_r([$a[1], $a[3]]);
?>
--EXPECT--
Array
(
[0] => 2
[1] => 4
)

@ -0,0 +1,20 @@
--TEST--
Testing nested array shortcut
--FILE--
<?php
print_r([1, 2, 3, ["foo" => "orange", "bar" => "apple", "baz" => "lemon"]]);
?>
--EXPECT--
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => Array
(
[foo] => orange
[bar] => apple
[baz] => lemon
)
)

@ -0,0 +1,11 @@
--TEST--
Bison weirdness
--SKIPIF--
<?php die("skip");?>
--FILE--
<?php
echo "blah-$foo\n";
?>
--EXPECTF--
Warning: Undefined variable $foo in %s on line %d
blah-

@ -0,0 +1,20 @@
--TEST--
Bug #18872 (class constant used as default parameter)
--SKIPIF--
<?php die("skip");?>
--FILE--
<?php
class FooBar {
const BIFF = 3;
}
function foo($biff = FooBar::BIFF) {
echo $biff . "\n";
}
foo();
foo();
?>
--EXPECT--
3
3

@ -0,0 +1,12 @@
--TEST--
Bug #19566 (get_declared_classes() segfaults)
--SKIPIF--
<?php die("skip");?>
--FILE--
<?php
class foo {}
$result = get_declared_classes();
var_dump(array_search('foo', $result));
?>
--EXPECTF--
int(%d)

@ -0,0 +1,35 @@
--TEST--
Bug #7515 (weird & invisible referencing of objects)
--SKIPIF--
<?php die("skip");?>
--FILE--
<?php
class obj {
function method() {}
}
$o = new stdClass;
$o->root = new obj();
ob_start();
var_dump($o);
$x=ob_get_contents();
ob_end_clean();
$o->root->method();
ob_start();
var_dump($o);
$y=ob_get_contents();
ob_end_clean();
if ($x == $y) {
print "success";
} else {
print "failure
x=$x
y=$y
";
}
?>
--EXPECT--
success
Loading…
Cancel
Save