mirror of
https://github.com/php/php-src.git
synced 2024-11-23 18:04:36 +08:00
Improved assert() according to expectations RFC.
See https://wiki.php.net/rfc/expectations Squashed commit of the following: commit3f3651a787
Author: Dmitry Stogov <dmitry@zend.com> Date: Mon Mar 2 11:56:33 2015 +0300 opcode 137 is used for ZEND_OP_DATA and con't be reused for ZEND_ASSERT_CHECK commitca8ecabf2a
Merge:24328ac
9dac923
Author: Dmitry Stogov <dmitry@zend.com> Date: Mon Mar 2 10:49:23 2015 +0300 Merge branch 'master' into assert * master: Update NEWS Fixed bug #69139 (Crash in gc_zval_possible_root on unserialize) windows only test Align entries format Align entries format for 5.6.7 Align entries format for 5.5.23 Bump header year Fixed bug #69144 (strtr not replacing with partly matching replace pairs) Fixed test? Revert mktime()/gmmktime()'s arginfo Update NEWS Fixed bug #69141 Missing arguments in reflection info for some builtin functions Add NEWS entry Remove useless date warning Fix ARG_INFO for levenshtein Fix ARG_INFO for levenshtein fix dir separator in tests Update NEWS Fixed bug #69085 (SoapClient's __call() type confusion through unserialize()). commit24328ac03f
Merge:021fd94
1cdee9a
Author: Dmitry Stogov <dmitry@zend.com> Date: Fri Feb 27 15:57:13 2015 +0300 Merge branch 'master' into assert * master: Fixed C++ support Fixed bug #69115 crash in mail Reorder Update NEWs Fixed bug #69121 (Segfault in get_current_user when script owner is not in passwd with ZTS build) Update News Fixed bug #69125 (Array numeric string as key) fix bug#68942's patch Fixed ability to build unspecialized executor Fixed bug #69124 (method name could not be used when by ref) Fixed a bug that header value is not terminated by '\0' when accessed through getenv(). Fixed a bug that header value is not terminated by '\0' when accessed through getenv(). commit021fd94ed1
Merge:49963eb
ace1f82
Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Feb 26 11:26:03 2015 +0300 Merge branch 'master' into assert * master: (59 commits) Improved ASSIGN_DIM handler Don't inline slow path Revert a part committted by mistake Fixed compilation warnings Fixed a bug that header value is not terminated by '\0' when accessed through getenv(). better name Improve fix for #69038 Update NEWs Fixed bug #69108 ("Segmentation fault" when (de)serializing SplObjectStorage) Added specialized versions of DO_FCALL handler: DO_ICALL - for internal functions DO_UCALL - for user functions DO_FCALL_BY_NAME - plain, most probably user, funcstions (not methods) Use cache_slot offsets instead of indexes (simplify run-time instructions) Split INIT_FCALL_BY_NAME inti INIT_FCALL_BY_NAME(CONST+STRING) and INIT_DYNAMIC_CALL(CONST-STRING|TMPVAR|CV) Support list($a, $b) = $a Avoid unnecassary check Make zend_array_destroy() to free the corresponding zend_array Eliminate check on the fast path Make current() and key() receive argument by value. Use Firebird default home folder, replace Interbase with Firebird Updated NEWS updated NEWS ... Conflicts: Zend/zend_vm_execute.h Zend/zend_vm_opcodes.c Zend/zend_vm_opcodes.h commit49963ebf9d
Merge:07b1f92
6b77959
Author: Dmitry Stogov <dmitry@zend.com> Date: Thu Feb 19 11:13:08 2015 +0300 Merge branch 'master' into assert * master: Implemented AST pretty-printer update NEWS to match the actual stuff in 5.6.6 update NEWS to match the actual stuff in 5.5.22 update NEWS(add missing entry for the enchant fix, and reorder the entries a bit) fix typo in bug# update NEWS fix email format update NEWS update 5.6.6 release date in NEWS Fix bug #69033 (Request may get env. variables from previous requests if PHP works as FastCGI) BFN fix test fix test fix test Fixed bug #65593 (Segfault when calling ob_start from output buffering callback) Updated NEWS add CVE 5.4.39 next Fix associativity to match Perl Blast off to space. Conflicts: Zend/zend_ast.c commit07b1f92ed6
Author: Dmitry Stogov <dmitry@zend.com> Date: Wed Feb 18 23:06:32 2015 +0300 fixed pretty-printer (support for "elseif") commit5a976c8d85
Author: Dmitry Stogov <dmitry@zend.com> Date: Wed Feb 18 19:50:08 2015 +0300 Fixed vaeious ptetty-printer issues commit69491e8e8e
Merge:8473157
3ddc246
Author: Dmitry Stogov <dmitry@zend.com> Date: Wed Feb 18 10:18:32 2015 +0300 Merge branch 'master' into assert * master: Set PHP_JSON_VERSION to 1.4.0 Remove unnecessary resource checks in openssl ext JSON is now maintained commit8473157fbb
Author: Dmitry Stogov <dmitry@zend.com> Date: Wed Feb 18 10:17:26 2015 +0300 Fixed typo and white spaces commit96de5ffc8d
Author: Dmitry Stogov <dmitry@zend.com> Date: Wed Feb 18 00:28:39 2015 +0300 Fixed assert() in namesapaces commit5eba069c28
Merge:4a2d9c0
d428bf2
Author: Dmitry Stogov <dmitry@zend.com> Date: Tue Feb 17 22:45:55 2015 +0300 Merge branch 'master' into assert * master: (25 commits) improve debugability in TS debug builds More UPGRADING, in particular on foreach Fixed bug #69038 (switch(SOMECONSTANT) misbehaves) for master Replace var is introduced abstain from using xmlCleanupParser fix TS build Fix bug #68942 (Use after free vulnerability in unserialize() with DateTimeZone) update news Fix bug #68942 (Use after free vulnerability in unserialize() with DateTimeZone) Port for for bug #68552 Fix bug #68942 (Use after free vulnerability in unserialize() with DateTimeZone) Update NEWS Fixed bug #69038 (switch(SOMECONSTANT) misbehaves) - BFN Don't read the local php.ini when Generating Phar When building phar shared, you can end up loading a previous phar.so that isn't compatible with the php cli being used to generate Phar here. - Fixed bug #67827 (broken detection of system crypt sha256/sha512 support) Delete json outdated package.xml made ZEND_TSRMLS_CACHE_* macros look like function calls - Fix merge - Fixed bug #67427 (SoapServer cannot handle large messages) patch by: brandt at docoloc dot de ... commit4a2d9c0953
Author: Dmitry Stogov <dmitry@zend.com> Date: Tue Feb 17 22:45:10 2015 +0300 Implemented AST pretty-printer to capture expression passed to assert() commit7a059b66d5
Merge:9973df7
3892eba
Author: Dmitry Stogov <dmitry@zend.com> Date: Mon Feb 16 18:42:28 2015 +0300 Merge branch 'expect' of github.com:krakjoe/php-src into assert * 'expect' of github.com:krakjoe/php-src: import expect Conflicts: Zend/zend_compile.c Zend/zend_execute_API.c Zend/zend_globals.h Zend/zend_vm_def.h Zend/zend_vm_execute.h Zend/zend_vm_opcodes.c Zend/zend_vm_opcodes.h ext/opcache/Optimizer/block_pass.c ext/opcache/Optimizer/pass1_5.c ext/standard/assert.c ext/standard/tests/assert/assert_error3.phpt commit3892eba2bf
Author: krakjoe <joe.watkins@live.co.uk> Date: Sun Feb 2 12:49:35 2014 +0000 import expect
This commit is contained in:
parent
9dac9237ab
commit
9a20323e19
12
Zend/tests/assert/expect_001.phpt
Normal file
12
Zend/tests/assert/expect_001.phpt
Normal file
@ -0,0 +1,12 @@
|
||||
--TEST--
|
||||
test passing assertion
|
||||
--INI--
|
||||
zend.assertions=1
|
||||
assert.exception=1
|
||||
--FILE--
|
||||
<?php
|
||||
assert(true);
|
||||
var_dump(true);
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(true)
|
16
Zend/tests/assert/expect_002.phpt
Normal file
16
Zend/tests/assert/expect_002.phpt
Normal file
@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
test failing assertion
|
||||
--INI--
|
||||
zend.assertions=1
|
||||
assert.exception=1
|
||||
--FILE--
|
||||
<?php
|
||||
assert(false);
|
||||
var_dump(true);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Uncaught exception 'AssertionException' with message 'assert(false)' in %sexpect_002.php:%d
|
||||
Stack trace:
|
||||
#0 %sexpect_002.php(%d): assert(false, 'assert(false)')
|
||||
#1 {main}
|
||||
thrown in %sexpect_002.php on line %d
|
15
Zend/tests/assert/expect_003.phpt
Normal file
15
Zend/tests/assert/expect_003.phpt
Normal file
@ -0,0 +1,15 @@
|
||||
--TEST--
|
||||
test catching failed assertion
|
||||
--INI--
|
||||
zend.assertions=1
|
||||
assert.exception=1
|
||||
--FILE--
|
||||
<?php
|
||||
try {
|
||||
assert(false);
|
||||
} catch (AssertionException $ex) {
|
||||
var_dump($ex->getMessage());
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
string(13) "assert(false)"
|
15
Zend/tests/assert/expect_004.phpt
Normal file
15
Zend/tests/assert/expect_004.phpt
Normal file
@ -0,0 +1,15 @@
|
||||
--TEST--
|
||||
test providing reason (fail)
|
||||
--INI--
|
||||
zend.assertions=1
|
||||
assert.exception=1
|
||||
--FILE--
|
||||
<?php
|
||||
try {
|
||||
assert(false, "I require this to succeed");
|
||||
} catch (AssertionException $ex) {
|
||||
var_dump($ex->getMessage());
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
string(25) "I require this to succeed"
|
17
Zend/tests/assert/expect_005.phpt
Normal file
17
Zend/tests/assert/expect_005.phpt
Normal file
@ -0,0 +1,17 @@
|
||||
--TEST--
|
||||
test providing reason (pass)
|
||||
--INI--
|
||||
zend.assertions=1
|
||||
assert.exception=1
|
||||
--FILE--
|
||||
<?php
|
||||
try {
|
||||
/* by passing we test there are no leaks upon success */
|
||||
assert(true, "I require this to succeed");
|
||||
} catch (AssertionException $ex) {
|
||||
var_dump($ex->getMessage());
|
||||
}
|
||||
var_dump(true);
|
||||
?>
|
||||
--EXPECT--
|
||||
bool(true)
|
14
Zend/tests/assert/expect_006.phpt
Normal file
14
Zend/tests/assert/expect_006.phpt
Normal file
@ -0,0 +1,14 @@
|
||||
--TEST--
|
||||
test looping assert (pass)
|
||||
--INI--
|
||||
zend.assertions=1
|
||||
assert.exception=1
|
||||
--FILE--
|
||||
<?php
|
||||
for($i=0; $i<100000; $i++) {
|
||||
assert ($i < 100000, "The universe should make sense");
|
||||
}
|
||||
var_dump(true);
|
||||
?>
|
||||
--EXPECT--
|
||||
bool(true)
|
22
Zend/tests/assert/expect_007.phpt
Normal file
22
Zend/tests/assert/expect_007.phpt
Normal file
@ -0,0 +1,22 @@
|
||||
--TEST--
|
||||
test compiled reason
|
||||
--INI--
|
||||
zend.assertions=1
|
||||
assert.exception=1
|
||||
--FILE--
|
||||
<?php
|
||||
$next = 1;
|
||||
$data = array(
|
||||
"key" => "X-HTTP ",
|
||||
"value" => "testing"
|
||||
);
|
||||
|
||||
class HeaderMalfunctionException extends AssertionException {}
|
||||
|
||||
assert (preg_match("~^([a-zA-Z0-9-]+)$~", $data["key"]), new HeaderMalfunctionException("malformed key found at {$next} \"{$data["key"]}\""));
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Uncaught exception 'HeaderMalfunctionException' with message 'malformed key found at 1 "X-HTTP "' in %sexpect_007.php:10
|
||||
Stack trace:
|
||||
#0 {main}
|
||||
thrown in %sexpect_007.php on line 10
|
34
Zend/tests/assert/expect_008.phpt
Normal file
34
Zend/tests/assert/expect_008.phpt
Normal file
@ -0,0 +1,34 @@
|
||||
--TEST--
|
||||
test disabled expectations have no ill side effects
|
||||
--INI--
|
||||
zend.assertions=0
|
||||
assert.exception=1
|
||||
--FILE--
|
||||
<?php
|
||||
class One {
|
||||
public function __construct() {
|
||||
assert($this || 0);
|
||||
}
|
||||
}
|
||||
class Two extends One {}
|
||||
|
||||
class OdEar extends AssertionException {}
|
||||
|
||||
function blah(){ return 1; }
|
||||
|
||||
$variable = 1;
|
||||
assert(true, "constant message");
|
||||
assert(($variable && $variable) || php_sapi_name(), new OdEar("constant message"));
|
||||
assert(false);
|
||||
assert(blah(), blah());
|
||||
|
||||
new Two();
|
||||
new Two();
|
||||
new Two();
|
||||
|
||||
assert (blah() || blah() || blah(), blah() || blah() || blah() || blah());
|
||||
|
||||
var_dump(true);
|
||||
?>
|
||||
--EXPECT--
|
||||
bool(true)
|
25
Zend/tests/assert/expect_009.phpt
Normal file
25
Zend/tests/assert/expect_009.phpt
Normal file
@ -0,0 +1,25 @@
|
||||
--TEST--
|
||||
test stack trace is correct from failed exception in extended class
|
||||
--INI--
|
||||
zend.assertions=1
|
||||
assert.exception=1
|
||||
--FILE--
|
||||
<?php
|
||||
class One {
|
||||
public function __construct() {
|
||||
}
|
||||
}
|
||||
class Two extends One {
|
||||
public function __construct() {
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
new Two();
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Uncaught exception 'AssertionException' with message 'assert(false)' in %sexpect_009.php:%d
|
||||
Stack trace:
|
||||
#0 %sexpect_009.php(%d): assert(false, 'assert(false)')
|
||||
#1 %sexpect_009.php(%d): Two->__construct()
|
||||
#2 {main}
|
||||
thrown in %sexpect_009.php on line %d
|
23
Zend/tests/assert/expect_010.phpt
Normal file
23
Zend/tests/assert/expect_010.phpt
Normal file
@ -0,0 +1,23 @@
|
||||
--TEST--
|
||||
test stack trace is correct from failed exception in extended class (parent implementing constructor)
|
||||
--INI--
|
||||
zend.assertions=1
|
||||
assert.exception=1
|
||||
--FILE--
|
||||
<?php
|
||||
class One {
|
||||
public function __construct() {
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
class Two extends One {}
|
||||
|
||||
new Two();
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Uncaught exception 'AssertionException' with message 'assert(false)' in %sexpect_010.php:%d
|
||||
Stack trace:
|
||||
#0 %sexpect_010.php(%d): assert(false, 'assert(false)')
|
||||
#1 %sexpect_010.php(%d): One->__construct()
|
||||
#2 {main}
|
||||
thrown in %sexpect_010.php on line %d
|
30
Zend/tests/assert/expect_011.phpt
Normal file
30
Zend/tests/assert/expect_011.phpt
Normal file
@ -0,0 +1,30 @@
|
||||
--TEST--
|
||||
test overloaded __toString on custom exception
|
||||
--INI--
|
||||
zend.assertions=1
|
||||
assert.exception=1
|
||||
--FILE--
|
||||
<?php
|
||||
class MyExpectations extends AssertionException {
|
||||
public function __toString() {
|
||||
return sprintf(
|
||||
"[Message]: %s", __CLASS__);
|
||||
}
|
||||
}
|
||||
|
||||
class One {
|
||||
public function __construct() {
|
||||
assert(false, (string) new MyExpectations());
|
||||
}
|
||||
}
|
||||
class Two extends One {}
|
||||
|
||||
new Two();
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Uncaught exception 'AssertionException' with message '[Message]: MyExpectations' in %sexpect_011.php:%d
|
||||
Stack trace:
|
||||
#0 %sexpect_011.php(%d): assert(false, '[Message]: MyEx...')
|
||||
#1 %sexpect_011.php(%d): One->__construct()
|
||||
#2 {main}
|
||||
thrown in %sexpect_011.php on line %d
|
21
Zend/tests/assert/expect_012.phpt
Normal file
21
Zend/tests/assert/expect_012.phpt
Normal file
@ -0,0 +1,21 @@
|
||||
--TEST--
|
||||
test enable/disable assertions at runtime
|
||||
--INI--
|
||||
zend.assertions=1
|
||||
assert.exception=1
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump((integer)ini_get("zend.assertions"));
|
||||
ini_set("zend.assertions", 0);
|
||||
var_dump((integer)ini_get("zend.assertions"));
|
||||
assert(false);
|
||||
ini_set("zend.assertions", 1);
|
||||
var_dump((integer)ini_get("zend.assertions"));
|
||||
assert(true);
|
||||
var_dump(true);
|
||||
?>
|
||||
--EXPECT--
|
||||
int(1)
|
||||
int(0)
|
||||
int(1)
|
||||
bool(true)
|
11
Zend/tests/assert/expect_013.phpt
Normal file
11
Zend/tests/assert/expect_013.phpt
Normal file
@ -0,0 +1,11 @@
|
||||
--TEST--
|
||||
test failing assertion when disabled (with return value)
|
||||
--INI--
|
||||
zend.assertions=0
|
||||
assert.exception=1
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump(assert(false));
|
||||
?>
|
||||
--EXPECT--
|
||||
bool(true)
|
12
Zend/tests/assert/expect_014.phpt
Normal file
12
Zend/tests/assert/expect_014.phpt
Normal file
@ -0,0 +1,12 @@
|
||||
--TEST--
|
||||
test failing assertion when disabled
|
||||
--INI--
|
||||
zend.assertions=0
|
||||
assert.exception=1
|
||||
--FILE--
|
||||
<?php
|
||||
assert(false);
|
||||
var_dump(true);
|
||||
?>
|
||||
--EXPECT--
|
||||
bool(true)
|
295
Zend/tests/assert/expect_015.phpt
Normal file
295
Zend/tests/assert/expect_015.phpt
Normal file
@ -0,0 +1,295 @@
|
||||
--TEST--
|
||||
AST pretty-peinter
|
||||
--INI--
|
||||
zend.assertions=1
|
||||
assert.exception=0
|
||||
--FILE--
|
||||
<?php
|
||||
assert(0 && ($a = function () {
|
||||
global $a, $$b;
|
||||
static $c, $d = 0;
|
||||
unset($e);
|
||||
$x = isset($a) && !empty($b) || eval($c);
|
||||
$x = $a ? $b : $c;
|
||||
$x = $a ?: $c;
|
||||
$x = $a ?? $b;
|
||||
list($a, $b, $c) = [1, 2=>'x', 'z'=>'c'];
|
||||
@foo();
|
||||
$y = clone $x;
|
||||
yield 1 => 2;
|
||||
}));
|
||||
|
||||
assert(0 && ($a = function &(array &$a, X $b = null) use ($c,&$d) : X {
|
||||
abstract class A extends B implements C, D {
|
||||
const X = 12;
|
||||
const Y = self::X, Z = "aaa";
|
||||
|
||||
public $a = 1, $b;
|
||||
protected $c;
|
||||
static private $d = null;
|
||||
|
||||
abstract function foo();
|
||||
|
||||
static private function f1() {
|
||||
for ($i = 0, $j = 100; $i < $j; $i++, --$j) {
|
||||
$s[$i] = $a[$j];
|
||||
}
|
||||
foreach ($a as $key => &$val) {
|
||||
print "$key => $val\n";
|
||||
}
|
||||
while ($s[$i]) {
|
||||
$i++;
|
||||
}
|
||||
do {
|
||||
$i--;
|
||||
} while ($s[$i]);
|
||||
$x = foo($a + 1, 4, ...[1,2,3]);
|
||||
$x = ${$a . "_1"}();
|
||||
$x = A::foo();
|
||||
$x = ${$a . "_1"}::foo();
|
||||
$x = A::${$a . "_1"}();
|
||||
$x = $x->foo();
|
||||
$x = ${$a . "_1"}->foo();
|
||||
$x = $x->{$a . "_1"}();
|
||||
$x->a = C::C;
|
||||
${$a . "_1"}->a = ${$a . "_1"}::C;
|
||||
$x->{a . "_1"} = C::C;
|
||||
$x = C::$z;
|
||||
$x = ${$a . "_1"}::$z;
|
||||
$x = C::${$z . "_1"};
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
assert(0 && ($a = function &(array &$a, X $b = null) use ($c,&$d) : X {
|
||||
final class A {
|
||||
final protected function f2() {
|
||||
if (!$x) {
|
||||
return 0;
|
||||
}
|
||||
if ($x == 1) {
|
||||
return 1;
|
||||
} else if ($x == 2) {
|
||||
return 2;
|
||||
} else if ($x == 3) {
|
||||
return 3;
|
||||
} else {
|
||||
if ($x == 9) {
|
||||
return 9;
|
||||
}
|
||||
L0:
|
||||
switch ($x) {
|
||||
case 4: break;
|
||||
case 5: continue;
|
||||
case 6: break 2;
|
||||
case 7: continue 2;
|
||||
case 8: goto L0;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
assert(0 && ($a = function &(array &$a, X $b = null) use ($c,&$d) : X {
|
||||
class A {
|
||||
use T1, T2 {
|
||||
T1::foo insteadof foo;
|
||||
T2::foo as bar;
|
||||
baz as public;
|
||||
ops as protected x;
|
||||
}
|
||||
use T3;
|
||||
}
|
||||
}));
|
||||
|
||||
assert(0 && ($a = function &(array &...$a) {
|
||||
declare(A=1,B=2);
|
||||
try {
|
||||
$i++;
|
||||
} catch (MyException $e) {
|
||||
echo 1;
|
||||
} catch (Exception $e) {
|
||||
echo 2;
|
||||
} finally {
|
||||
echo 3;
|
||||
}
|
||||
}));
|
||||
|
||||
assert(0 && ($a = function () {
|
||||
declare(C=1) { echo 1; }
|
||||
$x = '\'"`$a';
|
||||
$x = "'\"`$a";
|
||||
$x = `'"\`$a`;
|
||||
$x = "{$a}b";
|
||||
$x = "${a}b";
|
||||
$x = " {$foo->bar} ${$foo->bar} ";
|
||||
$x = " ${'---'} ";
|
||||
foo();
|
||||
\foo();
|
||||
namespace\foo();
|
||||
$x = foo;
|
||||
$x = \foo;
|
||||
$x = namespace\foo;
|
||||
$x = new foo();
|
||||
$x = new \foo();
|
||||
$x = new namespace\foo();
|
||||
if ($a) {
|
||||
} elseif ($b) {
|
||||
}
|
||||
}));
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: Unsupported declare 'A' in %sexpect_015.php on line %d
|
||||
|
||||
Warning: Unsupported declare 'B' in %sexpect_015.php on line %d
|
||||
|
||||
Warning: Unsupported declare 'C' in %sexpect_015.php on line %d
|
||||
|
||||
Warning: assert(): assert(0 && ($a = function () {
|
||||
global $a;
|
||||
global $$b;
|
||||
static $c;
|
||||
static $d = 0;
|
||||
unset($e);
|
||||
$x = isset($a) && !empty($b) || eval($c);
|
||||
$x = $a ? $b : $c;
|
||||
$x = $a ?: $c;
|
||||
$x = $a ?? $b;
|
||||
list($a, $b, $c) = [1, 2 => 'x', 'z' => 'c'];
|
||||
@foo();
|
||||
$y = clone $x;
|
||||
yield 1 => 2;
|
||||
})) failed in %sexpect_015.php on line %d
|
||||
|
||||
Warning: assert(): assert(0 && ($a = function &(array &$a, X $b = null) use($c, &$d): X {
|
||||
abstract class A extends B implements C, D {
|
||||
const X = 12;
|
||||
const Y = self::X, Z = 'aaa';
|
||||
public $a = 1, $b;
|
||||
protected $c;
|
||||
private static $d = null;
|
||||
public abstract function foo();
|
||||
|
||||
private static function f1() {
|
||||
for ($i = 0, $j = 100; $i < $j; $i++, --$j) {
|
||||
$s[$i] = $a[$j];
|
||||
}
|
||||
foreach ($a as $key => &$val) {
|
||||
print "$key => $val\n";
|
||||
}
|
||||
while ($s[$i]) {
|
||||
$i++;
|
||||
}
|
||||
do {
|
||||
$i--;
|
||||
} while ($s[$i]);
|
||||
$x = foo($a + 1, 4, ...[1, 2, 3]);
|
||||
$x = ${$a . '_1'}();
|
||||
$x = A::foo();
|
||||
$x = ${$a . '_1'}::foo();
|
||||
$x = A::${$a . '_1'}();
|
||||
$x = $x->foo();
|
||||
$x = ${$a . '_1'}->foo();
|
||||
$x = $x->{$a . '_1'}();
|
||||
$x->a = C::C;
|
||||
${$a . '_1'}->a = ${$a . '_1'}::C;
|
||||
$x->{a . '_1'} = C::C;
|
||||
$x = C::$z;
|
||||
$x = ${$a . '_1'}::$z;
|
||||
$x = C::${$z . '_1'};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})) failed in %sexpect_015.php on line %d
|
||||
|
||||
Warning: assert(): assert(0 && ($a = function &(array &$a, X $b = null) use($c, &$d): X {
|
||||
final class A {
|
||||
protected final function f2() {
|
||||
if (!$x) {
|
||||
return 0;
|
||||
}
|
||||
if ($x == 1) {
|
||||
return 1;
|
||||
} else if ($x == 2) {
|
||||
return 2;
|
||||
} else if ($x == 3) {
|
||||
return 3;
|
||||
} else {
|
||||
if ($x == 9) {
|
||||
return 9;
|
||||
}
|
||||
L0:
|
||||
switch ($x) {
|
||||
case 4:
|
||||
break;
|
||||
case 5:
|
||||
continue;
|
||||
case 6:
|
||||
break 2;
|
||||
case 7:
|
||||
continue 2;
|
||||
case 8:
|
||||
goto L0;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})) failed in %sexpect_015.php on line %d
|
||||
|
||||
Warning: assert(): assert(0 && ($a = function &(array &$a, X $b = null) use($c, &$d): X {
|
||||
class A {
|
||||
use T1, T2 {
|
||||
T1::foo insteadof foo;
|
||||
T2::foo as bar;
|
||||
baz as public;
|
||||
ops as protected x;
|
||||
}
|
||||
use T3;
|
||||
}
|
||||
|
||||
})) failed in %sexpect_015.php on line %d
|
||||
|
||||
Warning: assert(): assert(0 && ($a = function &(array &...$a) {
|
||||
declare(A = 1, B = 2);
|
||||
try {
|
||||
$i++;
|
||||
} catch (MyException $e) {
|
||||
echo 1;
|
||||
} catch (Exception $e) {
|
||||
echo 2;
|
||||
} finally {
|
||||
echo 3;
|
||||
}
|
||||
})) failed in %sexpect_015.php on line %d
|
||||
|
||||
Warning: assert(): assert(0 && ($a = function () {
|
||||
declare(C = 1) {
|
||||
echo 1;
|
||||
}
|
||||
$x = '\'"`$a';
|
||||
$x = "'\"`$a";
|
||||
$x = `'"\`$a`;
|
||||
$x = "{$a}b";
|
||||
$x = "{$a}b";
|
||||
$x = " {$foo->bar} {${$foo->bar}} ";
|
||||
$x = " ${---} ";
|
||||
foo();
|
||||
\foo();
|
||||
namespace\foo();
|
||||
$x = foo;
|
||||
$x = \foo;
|
||||
$x = namespace\foo;
|
||||
$x = new foo();
|
||||
$x = new \foo();
|
||||
$x = new namespace\foo();
|
||||
if ($a) {
|
||||
} elseif ($b) {
|
||||
}
|
||||
})) failed in %sexpect_015.php on line %d
|
24
Zend/tests/assert/expect_016.phpt
Normal file
24
Zend/tests/assert/expect_016.phpt
Normal file
@ -0,0 +1,24 @@
|
||||
--TEST--
|
||||
test enable/disable assertions at runtime (assertions not completely disabled)
|
||||
--INI--
|
||||
zend.assertions=0
|
||||
assert.exception=0
|
||||
--FILE--
|
||||
<?php
|
||||
ini_set("zend.assertions", 0);
|
||||
var_dump(assert(false));
|
||||
var_dump(assert(true));
|
||||
ini_set("zend.assertions", 1);
|
||||
var_dump(assert(false));
|
||||
var_dump(assert(true));
|
||||
ini_set("zend.assertions", -1);
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: assert(): assert(false) failed in %sexpect_016.php on line 6
|
||||
NULL
|
||||
bool(true)
|
||||
|
||||
Warning: zend.assertions may be completely enabled or disabled only in php.ini in %sexpect_016.php on line 8
|
19
Zend/tests/assert/expect_017.phpt
Normal file
19
Zend/tests/assert/expect_017.phpt
Normal file
@ -0,0 +1,19 @@
|
||||
--TEST--
|
||||
test enable/disable assertions at runtime (assertions completely disabled)
|
||||
--INI--
|
||||
zend.assertions=-1
|
||||
assert.exception=0
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump(assert(false));
|
||||
var_dump(assert(true));
|
||||
ini_set("zend.assertions", 0);
|
||||
ini_set("zend.assertions", 1);
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: zend.assertions may be completely enabled or disabled only in php.ini in %sexpect_017.php on line 4
|
||||
|
||||
Warning: zend.assertions may be completely enabled or disabled only in php.ini in %sexpect_017.php on line 5
|
33
Zend/tests/assert/expect_018.phpt
Normal file
33
Zend/tests/assert/expect_018.phpt
Normal file
@ -0,0 +1,33 @@
|
||||
--TEST--
|
||||
test assertions in namespace
|
||||
--INI--
|
||||
zend.assertions=1
|
||||
assert.exception=0
|
||||
--FILE--
|
||||
<?php
|
||||
namespace Foo;
|
||||
|
||||
ini_set("zend.assertions", 0);
|
||||
var_dump(\assert(false));
|
||||
var_dump(\assert(true));
|
||||
var_dump(assert(false));
|
||||
var_dump(assert(true));
|
||||
ini_set("zend.assertions", 1);
|
||||
var_dump(\assert(false));
|
||||
var_dump(\assert(true));
|
||||
var_dump(assert(false));
|
||||
var_dump(assert(true));
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: assert(): assert(false) failed in %sexpect_018.php on line 10
|
||||
NULL
|
||||
bool(true)
|
||||
|
||||
Warning: assert(): assert(false) failed in %sexpect_018.php on line 12
|
||||
NULL
|
||||
bool(true)
|
19
Zend/tests/assert/expect_019.phpt
Normal file
19
Zend/tests/assert/expect_019.phpt
Normal file
@ -0,0 +1,19 @@
|
||||
--TEST--
|
||||
test assertions in namespace (assertions completely disabled)
|
||||
--INI--
|
||||
zend.assertions=-1
|
||||
assert.exception=0
|
||||
--FILE--
|
||||
<?php
|
||||
namespace Foo;
|
||||
|
||||
var_dump(\assert(false));
|
||||
var_dump(\assert(true));
|
||||
var_dump(assert(false));
|
||||
var_dump(assert(true));
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
28
Zend/zend.c
28
Zend/zend.c
@ -99,9 +99,37 @@ static ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static ZEND_INI_MH(OnUpdateAssertions) /* {{{ */
|
||||
{
|
||||
zend_long *p, val;
|
||||
#ifndef ZTS
|
||||
char *base = (char *) mh_arg2;
|
||||
#else
|
||||
char *base;
|
||||
|
||||
base = (char *) ts_resource(*((int *) mh_arg2));
|
||||
#endif
|
||||
|
||||
p = (zend_long *) (base+(size_t) mh_arg1);
|
||||
|
||||
val = zend_atol(new_value->val, (int)new_value->len);
|
||||
|
||||
if (stage != ZEND_INI_STAGE_STARTUP &&
|
||||
stage != ZEND_INI_STAGE_SHUTDOWN &&
|
||||
*p != val &&
|
||||
(*p < 0 || val < 0)) {
|
||||
zend_error(E_WARNING, "zend.assertions may be completely enabled or disabled only in php.ini");
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
*p = val;
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
ZEND_INI_BEGIN()
|
||||
ZEND_INI_ENTRY("error_reporting", NULL, ZEND_INI_ALL, OnUpdateErrorReporting)
|
||||
STD_ZEND_INI_BOOLEAN("zend.assertions", "1", ZEND_INI_ALL, OnUpdateAssertions, assertions, zend_executor_globals, executor_globals)
|
||||
STD_ZEND_INI_BOOLEAN("zend.enable_gc", "1", ZEND_INI_ALL, OnUpdateGCEnabled, gc_enabled, zend_gc_globals, gc_globals)
|
||||
STD_ZEND_INI_BOOLEAN("zend.multibyte", "0", ZEND_INI_PERDIR, OnUpdateBool, multibyte, zend_compiler_globals, compiler_globals)
|
||||
ZEND_INI_ENTRY("zend.script_encoding", NULL, ZEND_INI_ALL, OnUpdateScriptEncoding)
|
||||
|
@ -2898,7 +2898,55 @@ int zend_compile_func_cuf(znode *result, zend_ast_list *args, zend_string *lcnam
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
int zend_try_compile_special_func(znode *result, zend_string *lcname, zend_ast_list *args) /* {{{ */
|
||||
|
||||
|
||||
static int zend_compile_assert(znode *result, zend_ast_list *args, zend_string *name, zend_function *fbc) /* {{{ */
|
||||
{
|
||||
if (EG(assertions) >= 0) {
|
||||
znode name_node;
|
||||
zend_op *opline;
|
||||
uint32_t check_op_number = get_next_op_number(CG(active_op_array));
|
||||
|
||||
zend_emit_op(NULL, ZEND_ASSERT_CHECK, NULL, NULL);
|
||||
|
||||
if (fbc) {
|
||||
name_node.op_type = IS_CONST;
|
||||
ZVAL_STR_COPY(&name_node.u.constant, name);
|
||||
|
||||
opline = zend_emit_op(NULL, ZEND_INIT_FCALL, NULL, &name_node);
|
||||
} else {
|
||||
opline = zend_emit_op(NULL, ZEND_INIT_NS_FCALL_BY_NAME, NULL, NULL);
|
||||
opline->op2_type = IS_CONST;
|
||||
opline->op2.constant = zend_add_ns_func_name_literal(
|
||||
CG(active_op_array), name);
|
||||
}
|
||||
zend_alloc_cache_slot(opline->op2.constant);
|
||||
|
||||
if (args->children == 1 &&
|
||||
(args->child[0]->kind != ZEND_AST_ZVAL ||
|
||||
Z_TYPE_P(zend_ast_get_zval(args->child[0])) != IS_STRING)) {
|
||||
/* add "assert(condition) as assertion message */
|
||||
zend_ast_list_add((zend_ast*)args,
|
||||
zend_ast_create_zval_from_str(
|
||||
zend_ast_export("assert(", args->child[0], ")")));
|
||||
}
|
||||
|
||||
zend_compile_call_common(result, (zend_ast*)args, fbc);
|
||||
|
||||
CG(active_op_array)->opcodes[check_op_number].op2.opline_num = get_next_op_number(CG(active_op_array));
|
||||
} else {
|
||||
if (!fbc) {
|
||||
zend_string_release(name);
|
||||
}
|
||||
result->op_type = IS_CONST;
|
||||
ZVAL_TRUE(&result->u.constant);
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
int zend_try_compile_special_func(znode *result, zend_string *lcname, zend_ast_list *args, zend_function *fbc) /* {{{ */
|
||||
{
|
||||
if (zend_string_equals_literal(lcname, "strlen")) {
|
||||
return zend_compile_func_strlen(result, args);
|
||||
@ -2930,6 +2978,8 @@ int zend_try_compile_special_func(znode *result, zend_string *lcname, zend_ast_l
|
||||
return zend_compile_func_cufa(result, args, lcname);
|
||||
} else if (zend_string_equals_literal(lcname, "call_user_func")) {
|
||||
return zend_compile_func_cuf(result, args, lcname);
|
||||
} else if (zend_string_equals_literal(lcname, "assert")) {
|
||||
return zend_compile_assert(result, args, lcname, fbc);
|
||||
} else {
|
||||
return FAILURE;
|
||||
}
|
||||
@ -2952,7 +3002,11 @@ void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
|
||||
{
|
||||
zend_bool runtime_resolution = zend_compile_function_name(&name_node, name_ast);
|
||||
if (runtime_resolution) {
|
||||
zend_compile_ns_call(result, &name_node, args_ast);
|
||||
if (zend_string_equals_literal_ci(zend_ast_get_str(name_ast), "assert")) {
|
||||
zend_compile_assert(result, args_ast, Z_STR(name_node.u.constant), NULL);
|
||||
} else {
|
||||
zend_compile_ns_call(result, &name_node, args_ast);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -2975,7 +3029,7 @@ void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
|
||||
}
|
||||
|
||||
if (zend_try_compile_special_func(result, lcname,
|
||||
zend_ast_get_list(args_ast)) == SUCCESS
|
||||
zend_ast_get_list(args_ast), fbc) == SUCCESS
|
||||
) {
|
||||
zend_string_release(lcname);
|
||||
zval_ptr_dtor(&name_node.u.constant);
|
||||
|
@ -225,6 +225,8 @@ struct _zend_executor_globals {
|
||||
zend_bool active;
|
||||
zend_bool valid_symbol_table;
|
||||
|
||||
zend_long assertions;
|
||||
|
||||
uint32_t ht_iterators_count; /* number of allocatd slots */
|
||||
uint32_t ht_iterators_used; /* number of used slots */
|
||||
HashTableIterator *ht_iterators;
|
||||
|
@ -773,6 +773,7 @@ ZEND_API int pass_two(zend_op_array *op_array)
|
||||
case ZEND_FE_RESET_RW:
|
||||
case ZEND_FE_FETCH_R:
|
||||
case ZEND_FE_FETCH_RW:
|
||||
case ZEND_ASSERT_CHECK:
|
||||
ZEND_PASS_TWO_UPDATE_JMP_TARGET(op_array, opline, opline->op2);
|
||||
break;
|
||||
case ZEND_VERIFY_RETURN_TYPE:
|
||||
|
@ -6839,4 +6839,20 @@ ZEND_VM_HANDLER(122, ZEND_DEFINED, CONST, ANY)
|
||||
ZEND_VM_NEXT_OPCODE();
|
||||
}
|
||||
|
||||
ZEND_VM_HANDLER(151, ZEND_ASSERT_CHECK, ANY, ANY)
|
||||
{
|
||||
USE_OPLINE
|
||||
|
||||
if (EG(assertions) <= 0) {
|
||||
zend_op *target = OP_JMP_ADDR(opline, opline->op2);
|
||||
|
||||
if (RETURN_VALUE_USED(target-1)) {
|
||||
ZVAL_TRUE(EX_VAR((target-1)->result.var));
|
||||
}
|
||||
ZEND_VM_JMP(target);
|
||||
} else {
|
||||
ZEND_VM_NEXT_OPCODE();
|
||||
}
|
||||
}
|
||||
|
||||
ZEND_VM_EXPORT_HANDLER(zend_do_fcall, ZEND_DO_FCALL)
|
||||
|
@ -1696,6 +1696,22 @@ static int ZEND_FASTCALL ZEND_FAST_RET_SPEC_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
|
||||
}
|
||||
}
|
||||
|
||||
static int ZEND_FASTCALL ZEND_ASSERT_CHECK_SPEC_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
|
||||
{
|
||||
USE_OPLINE
|
||||
|
||||
if (EG(assertions) <= 0) {
|
||||
zend_op *target = OP_JMP_ADDR(opline, opline->op2);
|
||||
|
||||
if (RETURN_VALUE_USED(target-1)) {
|
||||
ZVAL_TRUE(EX_VAR((target-1)->result.var));
|
||||
}
|
||||
ZEND_VM_JMP(target);
|
||||
} else {
|
||||
ZEND_VM_NEXT_OPCODE();
|
||||
}
|
||||
}
|
||||
|
||||
static int ZEND_FASTCALL ZEND_FETCH_CLASS_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
|
||||
{
|
||||
USE_OPLINE
|
||||
@ -41219,31 +41235,31 @@ void zend_init_opcodes_handlers(void)
|
||||
ZEND_USER_OPCODE_SPEC_HANDLER,
|
||||
ZEND_USER_OPCODE_SPEC_HANDLER,
|
||||
ZEND_USER_OPCODE_SPEC_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_NULL_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_ASSERT_CHECK_SPEC_HANDLER,
|
||||
ZEND_JMP_SET_SPEC_CONST_HANDLER,
|
||||
ZEND_JMP_SET_SPEC_CONST_HANDLER,
|
||||
ZEND_JMP_SET_SPEC_CONST_HANDLER,
|
||||
|
@ -173,7 +173,7 @@ const char *zend_vm_opcodes_map[171] = {
|
||||
"ZEND_ISSET_ISEMPTY_PROP_OBJ",
|
||||
"ZEND_HANDLE_EXCEPTION",
|
||||
"ZEND_USER_OPCODE",
|
||||
NULL,
|
||||
"ZEND_ASSERT_CHECK",
|
||||
"ZEND_JMP_SET",
|
||||
"ZEND_DECLARE_LAMBDA_FUNCTION",
|
||||
"ZEND_ADD_TRAIT",
|
||||
|
@ -173,6 +173,7 @@ END_EXTERN_C()
|
||||
#define ZEND_ISSET_ISEMPTY_PROP_OBJ 148
|
||||
#define ZEND_HANDLE_EXCEPTION 149
|
||||
#define ZEND_USER_OPCODE 150
|
||||
#define ZEND_ASSERT_CHECK 151
|
||||
#define ZEND_JMP_SET 152
|
||||
#define ZEND_DECLARE_LAMBDA_FUNCTION 153
|
||||
#define ZEND_ADD_TRAIT 154
|
||||
|
@ -188,7 +188,7 @@ warning_count = 'NULL'
|
||||
Magic, magic properties:
|
||||
mysqli->affected_rows = ''/NULL (''/NULL)
|
||||
|
||||
Warning: assert(): Assertion failed in %s on line %d
|
||||
Warning: assert(): assert(@mysqli_get_client_info() === @$mysqli->client_info) failed in %s on line %d
|
||||
mysqli->client_info = ''/NULL ('%s'/%s)
|
||||
mysqli->client_version = '%s'/integer ('%s'/integer)
|
||||
mysqli->errno = ''/NULL (''/NULL)
|
||||
@ -199,7 +199,7 @@ mysqli->sqlstate = ''/NULL (''/NULL)
|
||||
mysqli->host_info = ''/NULL (''/NULL)
|
||||
mysqli->info = ''/NULL (''/NULL)
|
||||
|
||||
Warning: assert(): Assertion failed in %s on line %d
|
||||
Warning: assert(): assert(@mysqli_thread_id($mysqli) > @$mysqli->thread_id) failed in %s on line %d
|
||||
mysqli->thread_id = ''/NULL (''/NULL)
|
||||
mysqli->protocol_version = ''/NULL (''/NULL)
|
||||
mysqli->server_info = ''/NULL (''/NULL)
|
||||
@ -261,7 +261,7 @@ warning_count = 'NULL'
|
||||
Magic, magic properties:
|
||||
mysqli->affected_rows = ''/NULL (''/NULL)
|
||||
|
||||
Warning: assert(): Assertion failed in %s on line %d
|
||||
Warning: assert(): assert(@mysqli_get_client_info() === @$mysqli->client_info) failed in %s on line %d
|
||||
mysqli->client_info = ''/NULL ('%s'/%s)
|
||||
mysqli->client_version = '%s'/integer ('%s'/integer)
|
||||
mysqli->errno = ''/NULL (''/NULL)
|
||||
@ -272,7 +272,7 @@ mysqli->sqlstate = ''/NULL (''/NULL)
|
||||
mysqli->host_info = ''/NULL (''/NULL)
|
||||
mysqli->info = ''/NULL (''/NULL)
|
||||
|
||||
Warning: assert(): Assertion failed in %s on line %d
|
||||
Warning: assert(): assert(@mysqli_thread_id($mysqli) > @$mysqli->thread_id) failed in %s on line %d
|
||||
mysqli->thread_id = ''/NULL (''/NULL)
|
||||
mysqli->protocol_version = ''/NULL (''/NULL)
|
||||
mysqli->server_info = ''/NULL (''/NULL)
|
||||
|
@ -171,6 +171,7 @@ static int find_code_blocks(zend_op_array *op_array, zend_cfg *cfg, zend_optimiz
|
||||
case ZEND_NEW:
|
||||
case ZEND_JMP_SET:
|
||||
case ZEND_COALESCE:
|
||||
case ZEND_ASSERT_CHECK:
|
||||
START_BLOCK_OP(ZEND_OP2(opline).opline_num);
|
||||
START_BLOCK_OP(opno + 1);
|
||||
break;
|
||||
@ -306,6 +307,7 @@ static int find_code_blocks(zend_op_array *op_array, zend_cfg *cfg, zend_optimiz
|
||||
case ZEND_COALESCE:
|
||||
case ZEND_FE_FETCH_R:
|
||||
case ZEND_FE_FETCH_RW:
|
||||
case ZEND_ASSERT_CHECK:
|
||||
cur_block->op2_to = &blocks[ZEND_OP2(opline).opline_num];
|
||||
/* break missing intentionally */
|
||||
default:
|
||||
|
@ -100,6 +100,7 @@ void zend_optimizer_nop_removal(zend_op_array *op_array)
|
||||
case ZEND_NEW:
|
||||
case ZEND_JMP_SET:
|
||||
case ZEND_COALESCE:
|
||||
case ZEND_ASSERT_CHECK:
|
||||
ZEND_OP2(opline).opline_num -= shiftlist[ZEND_OP2(opline).opline_num];
|
||||
break;
|
||||
case ZEND_JMPZNZ:
|
||||
|
@ -609,6 +609,7 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
|
||||
case ZEND_NEW:
|
||||
case ZEND_JMP_SET:
|
||||
case ZEND_COALESCE:
|
||||
case ZEND_ASSERT_CHECK:
|
||||
collect_constants = 0;
|
||||
break;
|
||||
case ZEND_FETCH_R:
|
||||
|
@ -495,6 +495,7 @@ static void zend_accel_optimize(zend_op_array *op_array,
|
||||
case ZEND_FE_RESET_RW:
|
||||
case ZEND_FE_FETCH_R:
|
||||
case ZEND_FE_FETCH_RW:
|
||||
case ZEND_ASSERT_CHECK:
|
||||
ZEND_PASS_TWO_UNDO_JMP_TARGET(op_array, opline, ZEND_OP2(opline));
|
||||
break;
|
||||
}
|
||||
@ -535,6 +536,7 @@ static void zend_accel_optimize(zend_op_array *op_array,
|
||||
case ZEND_FE_RESET_RW:
|
||||
case ZEND_FE_FETCH_R:
|
||||
case ZEND_FE_FETCH_RW:
|
||||
case ZEND_ASSERT_CHECK:
|
||||
ZEND_PASS_TWO_UPDATE_JMP_TARGET(op_array, opline, ZEND_OP2(opline));
|
||||
break;
|
||||
}
|
||||
|
@ -451,6 +451,7 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc
|
||||
case ZEND_FE_RESET_RW:
|
||||
case ZEND_FE_FETCH_R:
|
||||
case ZEND_FE_FETCH_RW:
|
||||
case ZEND_ASSERT_CHECK:
|
||||
ZEND_OP2(opline).jmp_addr = &new_opcodes[ZEND_OP2(opline).jmp_addr - op_array->opcodes];
|
||||
break;
|
||||
}
|
||||
|
@ -9,12 +9,14 @@ var_dump($standard->getClassNames());
|
||||
?>
|
||||
==DONE==
|
||||
--EXPECTF--
|
||||
array(3) {
|
||||
array(4) {
|
||||
[0]=>
|
||||
%s(22) "__PHP_Incomplete_Class"
|
||||
[1]=>
|
||||
%s(15) "php_user_filter"
|
||||
[2]=>
|
||||
%s(9) "Directory"
|
||||
[3]=>
|
||||
%s(18) "AssertionException"
|
||||
}
|
||||
==DONE==
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "php.h"
|
||||
#include "php_assert.h"
|
||||
#include "php_ini.h"
|
||||
#include "zend_exceptions.h"
|
||||
/* }}} */
|
||||
|
||||
ZEND_BEGIN_MODULE_GLOBALS(assert)
|
||||
@ -31,10 +32,13 @@ ZEND_BEGIN_MODULE_GLOBALS(assert)
|
||||
zend_bool bail;
|
||||
zend_bool warning;
|
||||
zend_bool quiet_eval;
|
||||
zend_bool exception;
|
||||
ZEND_END_MODULE_GLOBALS(assert)
|
||||
|
||||
ZEND_DECLARE_MODULE_GLOBALS(assert)
|
||||
|
||||
static zend_class_entry *assertion_exception_ce;
|
||||
|
||||
#ifdef ZTS
|
||||
#define ASSERTG(v) ZEND_TSRMG(assert_globals_id, zend_assert_globals *, v)
|
||||
#else
|
||||
@ -48,7 +52,8 @@ enum {
|
||||
ASSERT_CALLBACK,
|
||||
ASSERT_BAIL,
|
||||
ASSERT_WARNING,
|
||||
ASSERT_QUIET_EVAL
|
||||
ASSERT_QUIET_EVAL,
|
||||
ASSERT_EXCEPTION
|
||||
};
|
||||
|
||||
static PHP_INI_MH(OnChangeCallback) /* {{{ */
|
||||
@ -83,6 +88,7 @@ PHP_INI_BEGIN()
|
||||
STD_PHP_INI_ENTRY("assert.warning", "1", PHP_INI_ALL, OnUpdateBool, warning, zend_assert_globals, assert_globals)
|
||||
PHP_INI_ENTRY("assert.callback", NULL, PHP_INI_ALL, OnChangeCallback)
|
||||
STD_PHP_INI_ENTRY("assert.quiet_eval", "0", PHP_INI_ALL, OnUpdateBool, quiet_eval, zend_assert_globals, assert_globals)
|
||||
STD_PHP_INI_ENTRY("assert.exception", "0", PHP_INI_ALL, OnUpdateBool, exception, zend_assert_globals, assert_globals)
|
||||
PHP_INI_END()
|
||||
|
||||
static void php_assert_init_globals(zend_assert_globals *assert_globals_p) /* {{{ */
|
||||
@ -94,6 +100,8 @@ static void php_assert_init_globals(zend_assert_globals *assert_globals_p) /* {{
|
||||
|
||||
PHP_MINIT_FUNCTION(assert) /* {{{ */
|
||||
{
|
||||
zend_class_entry ce;
|
||||
|
||||
ZEND_INIT_MODULE_GLOBALS(assert, php_assert_init_globals, NULL);
|
||||
|
||||
REGISTER_INI_ENTRIES();
|
||||
@ -103,6 +111,10 @@ PHP_MINIT_FUNCTION(assert) /* {{{ */
|
||||
REGISTER_LONG_CONSTANT("ASSERT_BAIL", ASSERT_BAIL, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("ASSERT_WARNING", ASSERT_WARNING, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("ASSERT_QUIET_EVAL", ASSERT_QUIET_EVAL, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("ASSERT_EXCEPTION", ASSERT_EXCEPTION, CONST_CS|CONST_PERSISTENT);
|
||||
|
||||
INIT_CLASS_ENTRY(ce, "AssertionException", NULL);
|
||||
assertion_exception_ce = zend_register_internal_class_ex(&ce, zend_exception_get_default(TSRMLS_C));
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
@ -135,21 +147,21 @@ PHP_MINFO_FUNCTION(assert) /* {{{ */
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto int assert(string|bool assertion[, string description])
|
||||
/* {{{ proto int assert(string|bool assertion[, mixed description])
|
||||
Checks if assertion is false */
|
||||
PHP_FUNCTION(assert)
|
||||
{
|
||||
zval *assertion;
|
||||
zval *description = NULL;
|
||||
int val;
|
||||
size_t description_len = 0;
|
||||
char *myeval = NULL;
|
||||
char *compiled_string_description, *description = NULL;
|
||||
char *compiled_string_description;
|
||||
|
||||
if (! ASSERTG(active)) {
|
||||
RETURN_TRUE;
|
||||
}
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|s", &assertion, &description, &description_len) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|z", &assertion, &description) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -167,10 +179,12 @@ PHP_FUNCTION(assert)
|
||||
compiled_string_description = zend_make_compiled_string_description("assert code");
|
||||
if (zend_eval_stringl(myeval, Z_STRLEN_P(assertion), &retval, compiled_string_description) == FAILURE) {
|
||||
efree(compiled_string_description);
|
||||
if (description_len == 0) {
|
||||
if (!description) {
|
||||
php_error_docref(NULL, E_RECOVERABLE_ERROR, "Failure evaluating code: %s%s", PHP_EOL, myeval);
|
||||
} else {
|
||||
php_error_docref(NULL, E_RECOVERABLE_ERROR, "Failure evaluating code: %s%s:\"%s\"", PHP_EOL, description, myeval);
|
||||
zend_string *str = zval_get_string(description);
|
||||
php_error_docref(NULL, E_RECOVERABLE_ERROR, "Failure evaluating code: %s%s:\"%s\"", PHP_EOL, str->val, myeval);
|
||||
zend_string_release(str);
|
||||
}
|
||||
if (ASSERTG(bail)) {
|
||||
zend_bailout();
|
||||
@ -186,8 +200,7 @@ PHP_FUNCTION(assert)
|
||||
convert_to_boolean(&retval);
|
||||
val = Z_TYPE(retval) == IS_TRUE;
|
||||
} else {
|
||||
convert_to_boolean_ex(assertion);
|
||||
val = Z_TYPE_P(assertion) == IS_TRUE;
|
||||
val = zend_is_true(assertion);
|
||||
}
|
||||
|
||||
if (val) {
|
||||
@ -199,7 +212,7 @@ PHP_FUNCTION(assert)
|
||||
}
|
||||
|
||||
if (Z_TYPE(ASSERTG(callback)) != IS_UNDEF) {
|
||||
zval *args = safe_emalloc(description_len == 0 ? 3 : 4, sizeof(zval), 0);
|
||||
zval *args = safe_emalloc(!description ? 3 : 4, sizeof(zval), 0);
|
||||
zval retval;
|
||||
int i;
|
||||
uint lineno = zend_get_executed_lineno();
|
||||
@ -212,14 +225,13 @@ PHP_FUNCTION(assert)
|
||||
ZVAL_FALSE(&retval);
|
||||
|
||||
/* XXX do we want to check for error here? */
|
||||
if (description_len == 0) {
|
||||
if (!description) {
|
||||
call_user_function(CG(function_table), NULL, &ASSERTG(callback), &retval, 3, args);
|
||||
for (i = 0; i <= 2; i++) {
|
||||
zval_ptr_dtor(&(args[i]));
|
||||
}
|
||||
} else {
|
||||
ZVAL_STRINGL(&args[3], SAFE_STRING(description), description_len);
|
||||
|
||||
ZVAL_STR(&args[3], zval_get_string(description));
|
||||
call_user_function(CG(function_table), NULL, &ASSERTG(callback), &retval, 4, args);
|
||||
for (i = 0; i <= 3; i++) {
|
||||
zval_ptr_dtor(&(args[i]));
|
||||
@ -230,19 +242,33 @@ PHP_FUNCTION(assert)
|
||||
zval_ptr_dtor(&retval);
|
||||
}
|
||||
|
||||
if (ASSERTG(warning)) {
|
||||
if (description_len == 0) {
|
||||
if (ASSERTG(exception)) {
|
||||
if (!description) {
|
||||
zend_throw_exception(assertion_exception_ce, NULL, E_ERROR TSRMLS_CC);
|
||||
} else if (Z_TYPE_P(description) == IS_OBJECT &&
|
||||
instanceof_function(Z_OBJCE_P(description), assertion_exception_ce TSRMLS_CC)) {
|
||||
Z_ADDREF_P(description);
|
||||
zend_throw_exception_object(description TSRMLS_CC);
|
||||
} else {
|
||||
zend_string *str = zval_get_string(description);
|
||||
zend_throw_exception(assertion_exception_ce, str->val, E_ERROR TSRMLS_CC);
|
||||
zend_string_release(str);
|
||||
}
|
||||
} else if (ASSERTG(warning)) {
|
||||
if (!description) {
|
||||
if (myeval) {
|
||||
php_error_docref(NULL, E_WARNING, "Assertion \"%s\" failed", myeval);
|
||||
} else {
|
||||
php_error_docref(NULL, E_WARNING, "Assertion failed");
|
||||
}
|
||||
} else {
|
||||
zend_string *str = zval_get_string(description);
|
||||
if (myeval) {
|
||||
php_error_docref(NULL, E_WARNING, "%s: \"%s\" failed", description, myeval);
|
||||
php_error_docref(NULL, E_WARNING, "%s: \"%s\" failed", str->val, myeval);
|
||||
} else {
|
||||
php_error_docref(NULL, E_WARNING, "%s failed", description);
|
||||
php_error_docref(NULL, E_WARNING, "%s failed", str->val);
|
||||
}
|
||||
zend_string_release(str);
|
||||
}
|
||||
}
|
||||
|
||||
@ -329,6 +355,18 @@ PHP_FUNCTION(assert_options)
|
||||
}
|
||||
return;
|
||||
|
||||
case ASSERT_EXCEPTION:
|
||||
oldint = ASSERTG(exception);
|
||||
if (ac == 2) {
|
||||
zend_string *key = zend_string_init("assert.exception", sizeof("assert.exception")-1, 0);
|
||||
zend_string *val = zval_get_string(value);
|
||||
zend_alter_ini_entry_ex(key, val, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC);
|
||||
zend_string_release(val);
|
||||
zend_string_release(key);
|
||||
}
|
||||
RETURN_LONG(oldint);
|
||||
break;
|
||||
|
||||
default:
|
||||
php_error_docref(NULL, E_WARNING, "Unknown value %pd", what);
|
||||
break;
|
||||
|
@ -42,7 +42,7 @@ Warning: assert_options() expects at most 2 parameters, 3 given in %s on line %d
|
||||
|
||||
Warning: assert_options() expects parameter 1 to be integer, %unicode_string_optional% given in %s on line %d
|
||||
|
||||
Warning: assert(): Assertion failed in %s on line %d
|
||||
Warning: assert(): assert(0) failed in %s on line %d
|
||||
|
||||
Warning: assert(): Assertion failed in %s on line %d
|
||||
Warning: assert(): assert(0) failed in %s on line %d
|
||||
|
||||
|
@ -29,9 +29,9 @@ assert(0);
|
||||
string(2) "f1"
|
||||
f1 called
|
||||
|
||||
Warning: assert(): Assertion failed in %s on line 13
|
||||
Warning: assert(): assert(0) failed in %s on line 13
|
||||
string(2) "f1"
|
||||
string(2) "f2"
|
||||
f2 called
|
||||
|
||||
Warning: assert(): Assertion failed in %s on line 17
|
||||
Warning: assert(): assert(0) failed in %s on line 17
|
||||
|
@ -22,4 +22,4 @@ echo "If this is printed BAIL hasn't worked";
|
||||
int(0)
|
||||
f1 called
|
||||
|
||||
Warning: assert(): Assertion "0 != 0" failed in %s on line 10
|
||||
Warning: assert(): assert($sa): "0 != 0" failed in %s on line 10
|
||||
|
@ -26,7 +26,7 @@ var_dump($rao=assert_options(ASSERT_WARNING, 0));
|
||||
int(0)
|
||||
f1 called
|
||||
|
||||
Warning: assert(): Assertion "0 != 0" failed in %s on line 10
|
||||
Warning: assert(): assert($sa): "0 != 0" failed in %s on line 10
|
||||
NULL
|
||||
bool(true)
|
||||
int(1)
|
||||
|
@ -13,4 +13,4 @@ assert(0);
|
||||
--EXPECTF--
|
||||
Hello World!
|
||||
|
||||
Warning: assert(): Assertion failed in %s on line %d
|
||||
Warning: assert(): assert(0) failed in %s on line %d
|
||||
|
@ -17,8 +17,7 @@ function f1($script, $line, $message, $user_message)
|
||||
|
||||
//bail out on error
|
||||
var_dump($rao = assert_options(ASSERT_BAIL, 1));
|
||||
$sa = "0 != 0";
|
||||
var_dump($r2 = assert($sa));
|
||||
var_dump($r2 = assert("0 != 0"));
|
||||
echo "If this is printed BAIL hasn't worked";
|
||||
--EXPECTF--
|
||||
int(0)
|
||||
@ -26,5 +25,5 @@ int(0)
|
||||
Warning: Missing argument 4 for f1() in %s on line 2
|
||||
f1 called
|
||||
|
||||
Warning: assert(): Assertion "0 != 0" failed in %s on line 10
|
||||
Warning: assert(): Assertion "0 != 0" failed in %s on line 9
|
||||
|
||||
|
@ -10,12 +10,11 @@ error_reporting = -1
|
||||
display_errors = 1
|
||||
--FILE--
|
||||
<?php
|
||||
$sa = "0 $ 0";
|
||||
var_dump($r2 = assert($sa));
|
||||
var_dump($r2 = assert("0 $ 0"));
|
||||
--EXPECTF--
|
||||
|
||||
Parse error: syntax error, %s in %s(3) : assert code on line 1
|
||||
Parse error: syntax error, unexpected '$', expecting ';' in %s(2) : assert code on line 1
|
||||
|
||||
Catchable fatal error: assert(): Failure evaluating code:
|
||||
0 $ 0 in %s on line 3
|
||||
0 $ 0 in %s on line 2
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user