Re: [RFC] Deprecations for PHP 8.4

From: Date: Thu, 27 Jun 2024 17:20:06 +0000
Subject: Re: [RFC] Deprecations for PHP 8.4
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi

On 6/27/24 09:44, Markus Podar wrote:
👎 on deprecating it; if a gotcha with it is not clear (e.g. using it in different scopes, as this was brought up), I see this rather as a "documentation problem".
If one can easily use a function incorrectly in a way that is not *immediately* apparent, then I consider the function to be badly designed. In my book this includes all functions that rely on global state, because that will lead to spooky action from a distance sooner rather than later. Here's an example (https://3v4l.org/XNl3X):
    <?php
    function processInner($line) {
        $tok = strtok($line, ",");
        while ($tok !== false) {
            echo "Entry=$tok\n";
            $tok = strtok(",");
        }
    }
    function processOuter($csv) {
        $line = strtok($csv, "\n");
        while ($line !== false) {
            processInner($line);
            $line = strtok("\n");
        }
    }
    processOuter("foo,bar,baz\na,b,c\n1,2,3");
Each of the functions individually is "fine" (for an appropriate definition of fine), but combined they are buggy. This becomes worse when the processInner() function is part of a third party library you don't control. Do you check each update of that library to see if it added or removed any strtok() calls anywhere? Pointing towards the documentation is not an excuse for bad API design. Best regards Tim Düsterhus

Thread (68 messages)

« previous php.internals (#123946) next »