diff options
author | Dmitry Stogov <dmitry@zend.com> | 2015-06-29 12:58:07 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2015-06-29 12:58:07 +0300 |
commit | 642c3790925d6a692747d4a1a6ee02deef0b93b5 (patch) | |
tree | 76ad5303f618c3a689ab09ea9c12884dd69e32ff /Zend/tests/bug69957.phpt | |
parent | 1bba4452e7e5fa34470e9167e6c8b28afb42fdb7 (diff) | |
download | php-git-642c3790925d6a692747d4a1a6ee02deef0b93b5.tar.gz |
Prevent attempts of compile-time evaluation of invalid operators (e.g. division/modulo by zero and shift by negative number)
Diffstat (limited to 'Zend/tests/bug69957.phpt')
-rw-r--r-- | Zend/tests/bug69957.phpt | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/Zend/tests/bug69957.phpt b/Zend/tests/bug69957.phpt new file mode 100644 index 0000000000..3653df7d91 --- /dev/null +++ b/Zend/tests/bug69957.phpt @@ -0,0 +1,84 @@ +--TEST-- +Bug #69957 (Different ways of handling div/mod by zero) +--FILE-- +<?php + +try { + $divisor = 0; + $result = 1 / $divisor; + var_dump($result); +} catch (Throwable $t){ + echo "Variable div\n"; + printf("Type: %s\n", get_class($t)); + printf("Message: %s\n", $t->getMessage()); +} + +try { + $divisor = 0; + $result = 1 % $divisor; + var_dump($result); +} catch (Throwable $t){ + echo "\nVariable mod\n"; + printf("Type: %s\n", get_class($t)); + printf("Message: %s\n", $t->getMessage()); +} + +try { + $result = 1 / 0; + var_dump($result); +} catch (Throwable $t){ + echo "\nLiteral div\n"; + printf("Type: %s\n", get_class($t)); + printf("Message: %s\n", $t->getMessage()); +} + +try { + $result = 1 % 0; + var_dump($result); +} catch (Throwable $t){ + echo "\nLiteral mod\n"; + printf("Type: %s\n", get_class($t)); + printf("Message: %s\n", $t->getMessage()); +} + +try { + $result = 1 / 0.0; + var_dump($result); +} catch (Throwable $t){ + echo "\nDouble div\n"; + printf("Type: %s\n", get_class($t)); + printf("Message: %s\n", $t->getMessage()); +} + +try { + $result = 1 % 0.0; + var_dump($result); +} catch (Throwable $t){ + echo "\nDouble mod\n"; + printf("Type: %s\n", get_class($t)); + printf("Message: %s\n", $t->getMessage()); +} + +?> +--EXPECTF-- +Warning: Division by zero in %sbug69957.php on line %d +float(INF) + +Variable mod +Type: Exception +Message: Division by zero + +Warning: Division by zero in %sbug69957.php on line %d +float(INF) + +Literal mod +Type: Exception +Message: Division by zero + +Warning: Division by zero in %sbug69957.php on line %d +float(INF) + +Double mod +Type: Exception +Message: Division by zero + |