Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:15302 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41643 invoked by uid 1010); 7 Mar 2005 22:41:36 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 41628 invoked from network); 7 Mar 2005 22:41:36 -0000 Received: from unknown (HELO php.net) (127.0.0.1) by localhost with SMTP; 7 Mar 2005 22:41:36 -0000 X-Host-Fingerprint: 81.169.182.136 h59705.serverkompetenz.net Linux 2.4/2.6 Received: from ([81.169.182.136:48312] helo=strato.aixcept.de) by pb1.pair.com (ecelerity HEAD r(5124)) with SMTP id FC/B5-53294-F98DC224 for ; Mon, 07 Mar 2005 17:41:35 -0500 Received: from [192.168.1.3] (dsl-082-083-244-202.arcor-ip.net [82.83.244.202]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by strato.aixcept.de (Postfix) with ESMTP id 7ED3935C1D6; Mon, 7 Mar 2005 23:44:36 +0100 (CET) Date: Mon, 7 Mar 2005 23:39:39 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <971339830.20050307233939@marcus-boerger.de> To: Sara Golemon Cc: internals@lists.php.net In-Reply-To: <20050307221330.17528.qmail@lists.php.net> References: <20050307221330.17528.qmail@lists.php.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Using `throw` with expr or expr logic From: helly@php.net (Marcus Boerger) Hello Sara, patch looks correct anyway Andi or Zeev is needed here Monday, March 7, 2005, 11:13:30 PM, you wrote: > A user was asking about why he could perform statements such as: > $db = mysql_connect('localhost') or die('Unable to connect to database > server'); > But not: > $db = new mysqli('localhost') or throw('Unable to connect to database > server'); > The short answer, obviously, is that throw just doesn't behave that way. > Like echo(), it simply doesn't have a return value to give. > Then again.... neither do die() or exit(), yet they pretend to return > one.... > I've tried out the patch below with `make test` and it doesn't complain of > anything. Can a ZendHead take a look and ridicule or otherwise comment? > -Sara > Index: Zend/zend_compile.h > =================================================================== > RCS file: /repository/ZendEngine2/zend_compile.h,v > retrieving revision 1.302 > diff -u -r1.302 zend_compile.h > --- Zend/zend_compile.h 11 Feb 2005 22:26:45 -0000 1.302 > +++ Zend/zend_compile.h 7 Mar 2005 22:08:49 -0000 > @@ -396,7 +396,7 @@ > void zend_do_try(znode *try_token TSRMLS_DC); > void zend_do_begin_catch(znode *try_token, znode *catch_class, znode > *catch_var, zend_bool first_catch TSRMLS_DC); > void zend_do_end_catch(znode *try_token TSRMLS_DC); > -void zend_do_throw(znode *expr TSRMLS_DC); > +void zend_do_throw(znode *result, znode *expr TSRMLS_DC); > ZEND_API int do_bind_function(zend_op *opline, HashTable *function_table, > zend_bool compile_time); > ZEND_API zend_class_entry *do_bind_class(zend_op *opline, HashTable > *class_table, zend_bool compile_time TSRMLS_DC); > Index: Zend/zend_compile.c > =================================================================== > RCS file: /repository/ZendEngine2/zend_compile.c,v > retrieving revision 1.614 > diff -u -r1.614 zend_compile.c > --- Zend/zend_compile.c 6 Mar 2005 16:22:02 -0000 1.614 > +++ Zend/zend_compile.c 7 Mar 2005 22:08:49 -0000 > @@ -1670,7 +1670,7 @@ > CG(active_op_array)->opcodes[try_token->u.opline_num].extended_value = > get_next_op_number(CG(active_op_array)); > } > -void zend_do_throw(znode *expr TSRMLS_DC) > +void zend_do_throw(znode *result, znode *expr TSRMLS_DC) > { > zend_op *opline; > @@ -1678,6 +1678,10 @@ > opline->opcode = ZEND_THROW; > opline->op1 = *expr; > SET_UNUSED(opline->op2); > + > + result->op_type = IS_CONST; > + result->u.constant.type = IS_BOOL; > + result->u.constant.value.lval = 1; > } > ZEND_API void function_add_ref(zend_function *function) > Index: Zend/zend_language_parser.y > =================================================================== > RCS file: /repository/ZendEngine2/zend_language_parser.y,v > retrieving revision 1.155 > diff -u -r1.155 zend_language_parser.y > --- Zend/zend_language_parser.y 11 Feb 2005 22:26:45 -0000 1.155 > +++ Zend/zend_language_parser.y 7 Mar 2005 22:08:49 -0000 > @@ -110,7 +110,7 @@ > %token T_RETURN > %token T_TRY > %token T_CATCH > -%token T_THROW > +%right T_THROW > %token T_USE > %token T_GLOBAL > %right T_STATIC T_ABSTRACT T_FINAL T_PRIVATE T_PROTECTED T_PUBLIC > @@ -225,7 +225,6 @@ > T_VARIABLE ')' { zend_do_begin_catch(&$1, &$9, &$11, 1 TSRMLS_CC); } > '{' inner_statement_list '}' { zend_do_end_catch(&$1 TSRMLS_CC); } > additional_catches { zend_do_mark_last_catch(&$7, &$18 TSRMLS_CC); } > - | T_THROW expr ';' { zend_do_throw(&$2 TSRMLS_CC); } > ; > @@ -614,6 +613,7 @@ > | T_ARRAY '(' array_pair_list ')' { $$ = $3; } > | '`' encaps_list '`' { zend_do_shell_exec(&$$, &$2 TSRMLS_CC); } > | T_PRINT expr { zend_do_print(&$$, &$2 TSRMLS_CC); } > + | T_THROW expr { zend_do_throw(&$$, &$2 TSRMLS_CC); } > ; > function_call -- Best regards, Marcus mailto:helly@php.net