On 27/02/2021 16:23, Kamil Tekiela wrote:
I don't see why this would be such an issue. If the code fails for any
reason then an error is produced. The error might be surprising, but it is
not something that would cause problems.


Just addressing this argument, not the proposal itself, a function throwing an exception that previously failed silently absolutely could cause problems.

Consider this code:

function get_product($product_id) {
    $sql = "Select * From products Where product_id = '" . $dbWrapper->escape($product_id) . "'";
    return $dbWrapper->runQuery($sql);
}

If product_id is actually an integer column, this function is technically broken: given a non-integer input, it will produce an error in the database. However, with lax error handling, the calling code will simply treat this as the product not existing, and handle it gracefully.

If $dbWrapper->runQuery suddenly starts throwing exceptions, functions that were inadvertently relying on this behaviour will start failing, possibly with an uncaught exception propagating to the user.

The exception is certainly pointing out a real bug, and the function can easily be fixed once the problem is spotted, but the change has a real negative impact on the application.


To be clear, I am not saying I agree or disagree with this particular proposal. I note that the user could in this example update their DB wrapper to set the error mode explicitly, or to catch exceptions. I just wanted to show that "it only happens on error" doesn't mean the impact is zero.

Regards,

--
Rowan Tommins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to