php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52874 Refactor big if condition w/ collateral effects and nested ternary statements
Submitted: 2010-09-18 03:27 UTC Modified: 2018-03-10 14:29 UTC
From: cataphract@php.net Assigned: cmb (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: trunk-SVN-2010-09-18 (SVN) OS: Irrelevant
Private report: No CVE-ID: None
 [2010-09-18 03:27 UTC] cataphract@php.net
Description:
------------
Two if conditions (one in zend_std_read_property and another in zend_std_write_property) are very confusing and should be refactored. Here's one:

    493 	if (EXPECTED(property_info != NULL) &&
    494 	    ((EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
    495 	     property_info->offset >= 0) ?
    496 	        (zobj->properties ?
    497 	            ((variable_ptr = (zval**)zobj->properties_table[property_info->offset]) != NULL) :
    498 	            (*(variable_ptr = &zobj->properties_table[property_info->offset]) != NULL)) :
    499 	        (EXPECTED(zobj->properties != NULL) &&
    500 	          EXPECTED(zend_hash_quick_find(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, (void **) &variable_ptr) == SUCCESS)))) {
    501 		/* if we already have this value there, we don't actually need to do anything */

This is very non-obvious.

I've refactored the conditions, which I tested with no regressions in the tests.


Patches

refact_if (last revision 2010-09-18 01:27 UTC by cataphract@php.net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-18 03:27 UTC] cataphract@php.net
The following patch has been added/updated:

Patch Name: refact_if
Revision:   1284773271
URL:        http://bugs.php.net/patch-display.php?bug=52874&patch=refact_if&revision=1284773271
 [2010-09-18 03:31 UTC] cataphract@php.net
It's not just non-obvious. It also makes debugging harder. If I segfault on the if condition, my debugger will show it as occurring in the last line of the if.
 [2018-03-10 14:29 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2018-03-10 14:29 UTC] cmb@php.net
Apparently, the respective code has been already modified, so I'm
closing this ticket.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 22:01:29 2024 UTC