From c4bcb1697481d3a6549f228739f17dc081641491 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 27 Feb 2011 19:38:13 +0100 Subject: [PATCH 1/1] Enabler PHP natives assertion in debug and use Platal::assert() as a backend when assertions fail. Thus, you can write the following code: assert ('$toto != blah') If you run in debug mode, this will be evaluated and will raise an exception in case of error. If you run in production mode, this will juste be skipped. Signed-off-by: Florent Bruneau --- classes/plglobals.php | 1 + include/platal.inc.php | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/classes/plglobals.php b/classes/plglobals.php index d168037..fd11a25 100644 --- a/classes/plglobals.php +++ b/classes/plglobals.php @@ -135,6 +135,7 @@ class PlGlobals $this->baseurl = @trim($base .$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']), '/'); $this->baseurl_http = @trim('http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']), '/'); } + assert_options(ASSERT_ACTIVE, $this->debug != 0); $this->setLocale(); } diff --git a/include/platal.inc.php b/include/platal.inc.php index 0f18429..900220c 100644 --- a/include/platal.inc.php +++ b/include/platal.inc.php @@ -144,7 +144,14 @@ function pl_print_errors($html = false) } } +function pl_assert_cb($file, $line, $message) +{ + Platal::assert(false, "Assertion failed at $file:$line with message: $message"); +} + set_error_handler('pl_error_handler', E_ALL | E_STRICT); +assert_options(ASSERT_CALLBACK, 'pl_assert_cb'); +assert_options(ASSERT_WARNING, false); if (php_sapi_name() == 'cli') { register_shutdown_function('pl_print_errors'); } -- 2.1.4