Утверждают, что не работает в php. Так просто. Что я делаю неправильно?

Это как утверждают, что даже не называется. Я сбит с толку.

версия

:~/code/x/test$ php -v
PHP 7.0.11-1+deb.sury.org~xenial+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.11-1+deb.sury.org~xenial+1, Copyright (c) 1999-2016, by Zend Technologies

сценарий

:~/code/x/test$ cat x.php
<?php

print ("Hello\n");

assert_options(ASSERT_ACTIVE,true);
assert_options(ASSERT_BAIL,true);

assert(false);
assert(true);

print ("Bye\n");

когда я бегу

:~/code/x/test$ php x.php
Hello
Bye

Я ожидал, что программа завершится с исключением. Я схожу с ума?

7

Решение

Спасибо RiggsFolly.

Похоже, утверждения выключены из коробки на 7.0. В моем файле php.ini для zend.assertions было установлено значение -1, что означает, что они игнорируются. Я изменил настройку на 1.

[Assertion]
; Switch whether to compile assertions at all (to have no overhead at run-time)
; -1: Do not compile at all
;  0: Jump over assertion at run-time
;  1: Execute assertions
; Changing from or to a negative value is only possible in php.ini! (For turning assertions on and off at run-time, see assert.active, when zend.assertions = 1)
; Default Value: 1
; Development Value: 1
; Production Value: -1
; http://php.net/zend.assertions
zend.assertions = 1

Скрипт теперь работает как положено.

:~/code/x/test$ php x.php
Hello
PHP Warning:  assert(): assert(false) failed in /home/ubuntu/code/x/test/x.php on line 8
12

Другие решения

Других решений пока нет …