parent
c1d759de57
commit
4f095c301d
28 changed files with 645 additions and 4 deletions
@ -0,0 +1,23 @@ |
||||
<?php |
||||
function safe_write($fd, $data) |
||||
{ |
||||
$len = strlen($data); |
||||
do { |
||||
$w = fwrite($fd, $data); |
||||
$len -= $w; |
||||
} while ($len && ($data = substr($data, $w)) !== FALSE); |
||||
} |
||||
|
||||
function sync($tmp) |
||||
{ |
||||
global $pipe; |
||||
$data = "hello world"; |
||||
safe_write($pipe, $data); |
||||
} |
||||
|
||||
function main() |
||||
{ |
||||
global $pipe; |
||||
$pipes = stream_socket_pair(AF_UNIX, SOCK_STREAM, 0); |
||||
$pipe = $pipes[0]; |
||||
} |
||||
@ -0,0 +1,10 @@ |
||||
#include <phpx.h> |
||||
#include <phpx_func.h> |
||||
#include <php_func_decl.h> |
||||
|
||||
using namespace php; |
||||
|
||||
Int php_test(Int a, Var b, Str c, Array d) { |
||||
php_var_dump(d, 10); |
||||
return 0; |
||||
} |
||||
@ -0,0 +1,6 @@ |
||||
<?php |
||||
function main() |
||||
{ |
||||
$obj = (object)'ciao'; |
||||
echo $obj->scalar; // 输出 'ciao' |
||||
} |
||||
@ -0,0 +1,28 @@ |
||||
--TEST-- |
||||
adding objects to arrays |
||||
--FILE-- |
||||
<?php |
||||
|
||||
$a = array(1,2,3); |
||||
|
||||
$o = new stdclass; |
||||
$o->prop = "value"; |
||||
|
||||
try { |
||||
var_dump($a + $o); |
||||
} catch (Error $e) { |
||||
echo "\nException: " . $e->getMessage() . "\n"; |
||||
} |
||||
|
||||
$c = $a + $o; |
||||
var_dump($c); |
||||
|
||||
echo "Done\n"; |
||||
?> |
||||
--EXPECTF-- |
||||
Exception: Unsupported operand types: array + stdClass |
||||
|
||||
Fatal error: Uncaught TypeError: Unsupported operand types: array + stdClass in %s:%d |
||||
Stack trace: |
||||
#0 {main} |
||||
thrown in %s on line %d |
||||
@ -0,0 +1,28 @@ |
||||
--TEST-- |
||||
adding arrays to objects |
||||
--FILE-- |
||||
<?php |
||||
|
||||
$a = array(1,2,3); |
||||
|
||||
$o = new stdclass; |
||||
$o->prop = "value"; |
||||
|
||||
try { |
||||
var_dump($o + $a); |
||||
} catch (Error $e) { |
||||
echo "\nException: " . $e->getMessage() . "\n"; |
||||
} |
||||
|
||||
$c = $o + $a; |
||||
var_dump($c); |
||||
|
||||
echo "Done\n"; |
||||
?> |
||||
--EXPECTF-- |
||||
Exception: Unsupported operand types: stdClass + array |
||||
|
||||
Fatal error: Uncaught TypeError: Unsupported operand types: stdClass + array in %s:%d |
||||
Stack trace: |
||||
#0 {main} |
||||
thrown in %s on line %d |
||||
@ -0,0 +1,23 @@ |
||||
--TEST-- |
||||
adding numbers to arrays |
||||
--FILE-- |
||||
<?php |
||||
|
||||
$a = array(1,2,3); |
||||
|
||||
try { |
||||
var_dump($a + 5); |
||||
} catch (Error $e) { |
||||
echo "\nException: " . $e->getMessage() . "\n"; |
||||
} |
||||
|
||||
$c = $a + 5; |
||||
var_dump($c); |
||||
|
||||
echo "Done\n"; |
||||
?> |
||||
--EXPECTF-- |
||||
int(6) |
||||
int(6) |
||||
Done |
||||
|
||||
@ -0,0 +1,56 @@ |
||||
--TEST-- |
||||
adding numbers to strings |
||||
--INI-- |
||||
precision=14 |
||||
--FILE-- |
||||
<?php |
||||
|
||||
$i = 75636; |
||||
$s1 = "this is a string"; |
||||
$s2 = "876222numeric"; |
||||
$s3 = "48474874"; |
||||
$s4 = "25.68"; |
||||
|
||||
try { |
||||
$c = $i + $s1; |
||||
var_dump($c); |
||||
} catch (\TypeError $e) { |
||||
echo $e->getMessage() . \PHP_EOL; |
||||
} |
||||
$c = $i + $s2; |
||||
var_dump($c); |
||||
|
||||
$c = $i + $s3; |
||||
var_dump($c); |
||||
|
||||
$c_float = $i + floatval($s4); |
||||
var_dump($c_float); |
||||
|
||||
try { |
||||
$c = $s1 + $i; |
||||
var_dump($c); |
||||
} catch (\TypeError $e) { |
||||
echo $e->getMessage() . \PHP_EOL; |
||||
} |
||||
|
||||
$c = $s2 + $i; |
||||
var_dump($c); |
||||
|
||||
$c = $s3 + $i; |
||||
var_dump($c); |
||||
|
||||
$c_float3 = floatval($s4) + $i; |
||||
var_dump($c_float3); |
||||
|
||||
echo "Done\n"; |
||||
?> |
||||
--EXPECTF-- |
||||
int(75636) |
||||
int(951858) |
||||
int(48550510) |
||||
float(75661.68) |
||||
int(75636) |
||||
int(951858) |
||||
int(48550510) |
||||
float(75661.68) |
||||
Done |
||||
@ -0,0 +1,27 @@ |
||||
--TEST-- |
||||
adding strings to arrays |
||||
--FILE-- |
||||
<?php |
||||
|
||||
$a = array(1,2,3); |
||||
|
||||
$s1 = "some string"; |
||||
|
||||
try { |
||||
var_dump($a + $s1); |
||||
} catch (Error $e) { |
||||
echo "\nException: " . $e->getMessage() . "\n"; |
||||
} |
||||
|
||||
$c = $a + $s1; |
||||
var_dump($c); |
||||
|
||||
echo "Done\n"; |
||||
?> |
||||
--EXPECTF-- |
||||
Exception: Unsupported operand types: array + string |
||||
|
||||
Fatal error: Uncaught TypeError: Unsupported operand types: array + string in %s:%d |
||||
Stack trace: |
||||
#0 {main} |
||||
thrown in %s on line %d |
||||
@ -0,0 +1,18 @@ |
||||
--TEST-- |
||||
Compound array assignment with same variable |
||||
--FILE-- |
||||
<?php |
||||
function main() { |
||||
$ary = [[]]; |
||||
$ary[0] += $ary; |
||||
foreach ($ary as $v) { |
||||
var_dump($v); |
||||
} |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
array(1) { |
||||
[0]=> |
||||
array(0) { |
||||
} |
||||
} |
||||
@ -0,0 +1,21 @@ |
||||
--TEST-- |
||||
Compound array assign with undefined variables |
||||
--SKIPIF-- |
||||
<?php die('skip'); ?> |
||||
--FILE-- |
||||
<?php |
||||
$a[$b] += 1; |
||||
var_dump($a); |
||||
?> |
||||
--EXPECTF-- |
||||
Warning: Undefined variable $a in %s on line %d |
||||
|
||||
Warning: Undefined variable $b in %s on line %d |
||||
|
||||
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d |
||||
|
||||
Warning: Undefined array key "" in %s on line %d |
||||
array(1) { |
||||
[""]=> |
||||
int(1) |
||||
} |
||||
@ -0,0 +1,16 @@ |
||||
--TEST-- |
||||
'break' error (non positive integers) |
||||
--SKIPIF-- |
||||
<?php die('skip'); ?> |
||||
--FILE-- |
||||
<?php |
||||
function foo () { |
||||
break 0; |
||||
} |
||||
|
||||
function main() { |
||||
foo(); |
||||
} |
||||
?> |
||||
--EXPECTF-- |
||||
Fatal error: 'break' operator accepts only positive integers in %sbreak_error_001.php on line 3 |
||||
@ -0,0 +1,12 @@ |
||||
--TEST-- |
||||
'break' error (operator with non-integer operand) |
||||
--SKIPIF-- |
||||
<?php die('skip'); ?> |
||||
--FILE-- |
||||
<?php |
||||
function foo () { |
||||
break $x; |
||||
} |
||||
?> |
||||
--EXPECTF-- |
||||
Fatal error: 'break' operator with non-integer operand is no longer supported in %sbreak_error_002.php on line 3 |
||||
@ -0,0 +1,12 @@ |
||||
--TEST-- |
||||
'break' error (not in the loop context) |
||||
--SKIPIF-- |
||||
<?php die('skip'); ?> |
||||
--FILE-- |
||||
<?php |
||||
function foo () { |
||||
break; |
||||
} |
||||
?> |
||||
--EXPECTF-- |
||||
Fatal error: 'break' not in the 'loop' or 'switch' context in %sbreak_error_003.php on line 3 |
||||
@ -0,0 +1,17 @@ |
||||
--TEST-- |
||||
'break' error (wrong level) |
||||
--SKIPIF-- |
||||
<?php die('skip'); ?> |
||||
--FILE-- |
||||
<?php |
||||
function foo () { |
||||
while (1) { |
||||
break 2; |
||||
} |
||||
} |
||||
function main() { |
||||
foo(); |
||||
} |
||||
?> |
||||
--EXPECTF-- |
||||
Fatal error: Cannot 'break' 2 levels in %sbreak_error_004.php on line 4 |
||||
@ -0,0 +1,38 @@ |
||||
--TEST-- |
||||
Testing nested exceptions |
||||
--FILE-- |
||||
<?php |
||||
|
||||
try { |
||||
try { |
||||
try { |
||||
try { |
||||
throw new Exception(); |
||||
} catch (Exception $e) { |
||||
var_dump($e->getMessage()); |
||||
throw $e; |
||||
} |
||||
} catch (Exception $e) { |
||||
var_dump($e->getMessage()); |
||||
throw $e; |
||||
} |
||||
} catch (Exception $e) { |
||||
var_dump($e->getMessage()); |
||||
throw $e; |
||||
} |
||||
} catch (Exception $e) { |
||||
var_dump($e->getMessage()); |
||||
throw $e; |
||||
} |
||||
|
||||
?> |
||||
--EXPECTF-- |
||||
string(0) "" |
||||
string(0) "" |
||||
string(0) "" |
||||
string(0) "" |
||||
|
||||
Fatal error: Uncaught Exception in %s:%d |
||||
Stack trace: |
||||
#0 {main} |
||||
thrown in %s on line %d |
||||
@ -0,0 +1,21 @@ |
||||
--TEST-- |
||||
Testing exception and GOTO |
||||
--SKIPIF-- |
||||
<?php die('skip'); ?> |
||||
--FILE-- |
||||
<?php |
||||
|
||||
goto foo; |
||||
|
||||
try { |
||||
print 1; |
||||
|
||||
foo: |
||||
print 2; |
||||
} catch (Exception $e) { |
||||
|
||||
} |
||||
|
||||
?> |
||||
--EXPECT-- |
||||
2 |
||||
@ -0,0 +1,13 @@ |
||||
--TEST-- |
||||
Throwing exception in global scope |
||||
--FILE-- |
||||
<?php |
||||
|
||||
throw new Exception(1); |
||||
|
||||
?> |
||||
--EXPECTF-- |
||||
Fatal error: Uncaught Exception: 1 in %s:%d |
||||
Stack trace: |
||||
#0 {main} |
||||
thrown in %s on line %d |
||||
@ -0,0 +1,15 @@ |
||||
--TEST-- |
||||
Trying to throw a non-object |
||||
--SKIPIF-- |
||||
<?php die('skip'); ?> |
||||
--FILE-- |
||||
<?php |
||||
|
||||
throw 1; |
||||
|
||||
?> |
||||
--EXPECTF-- |
||||
Fatal error: Uncaught Error: Can only throw objects in %s:%d |
||||
Stack trace: |
||||
#0 {main} |
||||
thrown in %s on line %d |
||||
@ -0,0 +1,35 @@ |
||||
--TEST-- |
||||
Setting previous exception |
||||
--FILE-- |
||||
<?php |
||||
|
||||
try { |
||||
try { |
||||
throw new Exception("First", 1, new Exception("Another", 0, NULL)); |
||||
} |
||||
catch (Exception $e) { |
||||
throw new Exception("Second", 2, $e); |
||||
} |
||||
} |
||||
catch (Exception $e) { |
||||
throw new Exception("Third", 3, $e); |
||||
} |
||||
|
||||
?> |
||||
--EXPECTF-- |
||||
Fatal error: Uncaught Exception: Another in %s |
||||
Stack trace: |
||||
#0 {main} |
||||
|
||||
Next Exception: First in %s |
||||
Stack trace: |
||||
#0 {main} |
||||
|
||||
Next Exception: Second in %s |
||||
Stack trace: |
||||
#0 {main} |
||||
|
||||
Next Exception: Third in %s |
||||
Stack trace: |
||||
#0 {main} |
||||
thrown in %s |
||||
@ -0,0 +1,17 @@ |
||||
--TEST-- |
||||
Test exception doesn't cause RSHUTDOWN bypass, variation 0 |
||||
--INI-- |
||||
zend.assertions=1 |
||||
--FILE-- |
||||
<?php |
||||
|
||||
define ("XXXXX", 1); |
||||
assert(false); |
||||
|
||||
?> |
||||
--EXPECTF-- |
||||
Fatal error: Uncaught AssertionError %s |
||||
Stack trace: |
||||
#0 [internal function]: assert(false) |
||||
#1 {main} |
||||
thrown in %s |
||||
@ -0,0 +1,20 @@ |
||||
--TEST-- |
||||
Exceptions on improper access to string |
||||
--FILE-- |
||||
<?php |
||||
$s = "ABC"; |
||||
try { |
||||
$s[] = "D"; |
||||
} catch (Error $e) { |
||||
echo "\nException: " . $e->getMessage() . " in " , $e->getFile() . " on line " . $e->getLine() . "\n"; |
||||
} |
||||
|
||||
$s[] = "D"; |
||||
?> |
||||
--EXPECTF-- |
||||
Exception: [] operator not supported for strings in %s |
||||
|
||||
Fatal error: Uncaught Error: [] operator not supported for strings %s |
||||
Stack trace: |
||||
#0 {main} |
||||
thrown in %s |
||||
@ -0,0 +1,14 @@ |
||||
--TEST-- |
||||
Testing throw exception doesn't crash with wrong params, variant 2 |
||||
--FILE-- |
||||
<?php |
||||
|
||||
throw new Exception(new stdClass); |
||||
|
||||
?> |
||||
--EXPECTF-- |
||||
Fatal error: Uncaught TypeError: Exception::__construct(): Argument #1 ($message) must be of type string, stdClass given in %s:%d |
||||
Stack trace: |
||||
#0 %s: Exception->__construct(Object(stdClass)) |
||||
#1 {main} |
||||
thrown in %s on line %d |
||||
@ -0,0 +1,14 @@ |
||||
--TEST-- |
||||
Testing throw exception doesn't crash with wrong params, variant 4 |
||||
--FILE-- |
||||
<?php |
||||
|
||||
throw new Error(new stdClass); |
||||
|
||||
?> |
||||
--EXPECTF-- |
||||
Fatal error: Uncaught TypeError: Error::__construct(): Argument #1 ($message) must be of type string, stdClass given in %s:%d |
||||
Stack trace: |
||||
#0 %s: Error->__construct(Object(stdClass)) |
||||
#1 {main} |
||||
thrown in %s on line %d |
||||
@ -0,0 +1,19 @@ |
||||
--TEST-- |
||||
XORing arrays |
||||
--FILE-- |
||||
<?php |
||||
|
||||
$a = array(1,2,3); |
||||
$b = array(); |
||||
|
||||
try { |
||||
$c = $a ^ $b; |
||||
} catch (TypeError $e) { |
||||
echo $e->getMessage(), "\n"; |
||||
} |
||||
|
||||
echo "Done\n"; |
||||
?> |
||||
--EXPECT-- |
||||
Unsupported operand types: array ^ array |
||||
Done |
||||
@ -0,0 +1,39 @@ |
||||
--TEST-- |
||||
XORing strings |
||||
--FILE-- |
||||
<?php |
||||
|
||||
$s = "123"; |
||||
$s1 = "234"; |
||||
var_dump(bin2hex($s ^ $s1)); |
||||
|
||||
$s = "1235"; |
||||
$s1 = "234"; |
||||
var_dump(bin2hex($s ^ $s1)); |
||||
|
||||
$s = "some"; |
||||
$s1 = "test"; |
||||
var_dump(bin2hex($s ^ $s1)); |
||||
|
||||
$s = "some long"; |
||||
$s1 = "test"; |
||||
var_dump(bin2hex($s ^ $s1)); |
||||
|
||||
$s = "some"; |
||||
$s1 = "test long"; |
||||
var_dump(bin2hex($s ^ $s1)); |
||||
|
||||
$s = "some"; |
||||
$s ^= "test long"; |
||||
var_dump(bin2hex($s)); |
||||
|
||||
echo "Done\n"; |
||||
?> |
||||
--EXPECT-- |
||||
string(6) "030107" |
||||
string(6) "030107" |
||||
string(8) "070a1e11" |
||||
string(8) "070a1e11" |
||||
string(8) "070a1e11" |
||||
string(8) "070a1e11" |
||||
Done |
||||
@ -0,0 +1,19 @@ |
||||
--TEST-- |
||||
XORing booleans |
||||
--FILE-- |
||||
<?php |
||||
|
||||
$t = true; |
||||
$f = false; |
||||
|
||||
var_dump($t ^ $f); |
||||
var_dump($t ^ $t); |
||||
var_dump($f ^ $f); |
||||
|
||||
echo "Done\n"; |
||||
?> |
||||
--EXPECT-- |
||||
int(1) |
||||
int(0) |
||||
int(0) |
||||
Done |
||||
@ -0,0 +1,12 @@ |
||||
--TEST-- |
||||
Operator precedence |
||||
--FILE-- |
||||
<?php |
||||
|
||||
var_dump((object)1 instanceof stdClass); |
||||
var_dump(! (object)1 instanceof Exception); |
||||
|
||||
?> |
||||
--EXPECT-- |
||||
bool(true) |
||||
bool(true) |
||||
Loading…
Reference in new issue