note 54477 modified in function.apd-croak by danbrown

From: Date: Thu, 18 Feb 2010 14:29:59 +0000
Subject: note 54477 modified in function.apd-croak by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-166133@lists.php.net to get a copy of this message
A function that "ASSERTS", ie that dies if the boolean in parameter is false ex: verify( $myDatabase->Connect() ); <?php function verify( $bResult ) { if (!bResult) { echo "<hr><h1>ERROR</h1><hr>"; echo "<pre>Last call arguments:\n"; for($i=0;$i<func_num_args();$i++) { echo "&rarr;"; print_r( func_get_arg ($i) ); echo "&larr;\n"; } if (sizeof($_GET)) { echo "<hr>GET VARS\n"; print_r( $_GET ); } if (sizeof($_POST)) { echo "<hr>POST VARS\n"; print_r( $_POST ); } if (sizeof($_SERVER)) { echo "<hr>SERVER VARS\n"; print_r( $_SERVER ); } if (sizeof($_COOKIE )) { echo "<hr>COOKIE VARS\n"; print_r( $_COOKIE ); } // Disable if not on a protected server if (sizeof($_SESSION )) { echo "<hr>SESSION VARS\n"; print_r( $_SESSION ); } echo "</pre>"; echo "<hr>"; if (function_exists("apd_callstack")) { apd_croak("Error !"); } else { die(1); } } } ?> --was-- // A function that "ASSERTS", ie that dies if the boolean in parameter is false // ex: verify( $myDatabase->Connect() ); function verify( $bResult ) { if (!bResult) { echo "<hr><h1>ERROR</h1><hr>"; echo "<pre>Last call arguments:\n"; for($i=0;$i<func_num_args();$i++) { echo "&rarr;"; print_r( func_get_arg ($i) ); echo "&larr;\n"; } if (sizeof($_GET)) { echo "<hr>GET VARS\n"; print_r( $_GET ); } if (sizeof($_POST)) { echo "<hr>POST VARS\n"; print_r( $_POST ); } if (sizeof($_SERVER)) { echo "<hr>SERVER VARS\n"; print_r( $_SERVER ); } if (sizeof($_COOKIE )) { echo "<hr>COOKIE VARS\n"; print_r( $_COOKIE ); } // Disable if not on a protected server if (sizeof($_SESSION )) { echo "<hr>SESSION VARS\n"; print_r( $_SESSION ); } echo "</pre>"; echo "<hr>"; if (function_exists("apd_callstack")) { apd_croak("Error !"); } else { die(1); } } } http://php.net/manual/en/function.apd-croak.php

« previous php.notes (#166133) next »