function bar() { $v1 = foo1(0); var_dump($v1); $v2 = foo2(0); var_dump($v2); $v3 = foo3(0); var_dump($v3); }
function foo1() { return NAN * NAN; } function foo2() { return NAN * 2; } function foo3() { return INF * NAN; } function foo4() { return 2.0 * INF; } function foo5() { return INF * INF; } function foo6($a) { return $a * 2.0; } var_dump(foo1()); var_dump(foo2()); var_dump(foo3()); var_dump(foo4()); var_dump(foo5()); var_dump(foo6(3.1));
break; } } catch (Exception $e) { echo "wrong\n"; } return; } function foo2() { try { switch (1) { case 0: try { dummy: throw new Exception('aaa'); } catch (Exception $e) { echo "correct\n"; } break; case 1: goto dummy; break; } } catch (Exception $e) { echo "wrong\n"; } return; } foo(); foo1(); foo2();
return $x - $x + 3; } function foo5($x) { return $x + 3 - $x; } function foo6($x) { return 0 - $x; } function foo7($x) { return $x - 0; } function foo8($x) { return $x - 1; } function foo9($x) { return 1 - $x; } var_dump(foo1(5, 2)); var_dump(foo2(1, 2)); var_dump(foo3(-3)); var_dump(foo4(5)); var_dump(foo5(5)); var_dump(foo6(-3)); var_dump(foo7(3)); var_dump(foo8(4)); var_dump(foo9(-2));
<?php error_reporting(E_ALL); function foo1($arg) { } function foo2($arg) { } function foo3($arg) { echo $undef3; throw new Exception("test"); } try { @error_reporting(@foo1(@foo2(@foo3()))); } catch (Exception $e) { } var_dump(error_reporting()); echo "Done\n";
<?php error_reporting(E_ALL); function foo1($arg) { } function foo2($arg) { } function foo3($arg) { error_reporting(E_ALL | E_STRICT); echo $undef3; throw new Exception("test"); } try { @foo1(@foo2(@foo3())); } catch (Exception $e) { } var_dump(error_reporting()); echo "Done\n";
switch ($i) { case 1: doX(); break; case 2: doY(); break; case 3: // NOK {{This case's code block is the same as the block for the case on line 21.}} doX(); break; case 4: case 5: case 6: doA(); case 7: break; default: break; } $condition ? foo1() : foo1(); // NOK {{This conditional operation returns the same value whether the condition is "true" or "false".}} $condition ? $nestedCondition ? foo1() : foo2() : $nestedCondition ? foo1() : foo2(); // NOK $condition ? $nestedCondition ? foo1() : foo1() : foo2(); // NOK false ? false ? foo(3) : foo(4) : foo(5); // OK false ? false ? foo(1) : foo(1) : foo(5); // NOK false ? false ? foo($b) : foo($b) : foo(5);
<?php error_reporting(E_ALL); function foo($arg) { echo @$nonex_foo; } function bar() { echo @$nonex_bar; throw new Exception("test"); } function foo1() { echo $undef1; error_reporting(E_ALL | E_STRICT); echo $undef2; } try { @foo(@bar(@foo1())); } catch (Exception $e) { } var_dump(error_reporting()); echo "Done\n";
function foo($a) { foo1($a); }
function foo2() { return NAN + NAN; } function foo3() { return NAN + 0.0; } function foo4() { return NAN + 1.1; } function foo5() { return NAN + INF; } function foo6() { return INF + INF; } function foo7() { return 6 + INF; } var_dump(foo1(true)); var_dump(foo2()); var_dump(foo3()); var_dump(foo4()); var_dump(foo5()); var_dump(foo6()); var_dump(foo7());
<?php function foo1($a, $b) { return $a - 4 + ($b - 9); } function foo2($a, $b) { return $a - 3 + 7; } function foo3($a, $b) { return $a - 3 - 7; } function foo4($a, $b) { return $a - 4 + ($b + 9); } $vals = array(array(0, 0), array(1, 1), array(-3, 5), array(5, -3), array(20, -50), array(20, 0)); foreach ($vals as list($a, $b)) { var_dump(foo1($a, $b)); var_dump(foo2($a, $b)); var_dump(foo3($a, $b)); var_dump(foo4($a, $b)); }
function bar1($x, $y) { return $x > 10 ? foo1($x - $y, $y) : $y; }
<?php /** *func_get_args() *func_get_arg() */ //func_get_args() function foo1() { var_dump(func_get_args()); } foo1(2, 3, 4, 'A', time()); //func_get_arg() function foo2() { //func_get_ var_dump(func_get_arg(1)); } foo2(2, 4, 5);
function dead() { echo "Bad call\n"; } $i = 0; $a[$i = 1][++$i](); $a = -1; function foo1() { global $a; return ++$a; } $arr = array(array(0, 0), 0); $brr = array(0, 0, array(0, 0, 0, 5), 0); $crr = array(0, 0, 0, 0, array(0, 0, 0, 0, 0, 10), 0, 0); $arr[foo1()][foo1()] = $brr[foo1()][foo1()] + $crr[foo1()][foo1()]; $val = $arr[0][1]; echo "Expect 15 and get...{$val}\n"; $x = array(array(0), 0); function mod($b) { global $x; $x = $b; return 0; } $x1 = array(array(1), 1); $x2 = array(array(2), 2); $x3 = array(array(3), 3); $bx = array(10); $x[mod($x1)][mod($x2)] = $bx[mod($x3)]; // expecting 10,3
<?php function foo1() { try { throw new Exception("not catch"); return true; } finally { try { throw new Exception("catched"); } catch (Exception $e) { } } } try { $foo = foo1(); var_dump($foo); } catch (Exception $e) { do { var_dump($e->getMessage()); } while ($e = $e->getPrevious()); } function foo2() { try { try { throw new Exception("catched"); return true; } finally { try { throw new Exception("catched");