Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103800 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 17519 invoked from network); 23 Jan 2019 18:15:37 -0000 Received: from unknown (HELO mail-ua1-f41.google.com) (209.85.222.41) by pb1.pair.com with SMTP; 23 Jan 2019 18:15:37 -0000 Received: by mail-ua1-f41.google.com with SMTP id j3so798682uap.3 for ; Wed, 23 Jan 2019 06:53:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=kaai28x9FG9xqqC3zpoCF0gZijWD/V2hk7A8DunPxfw=; b=cBz0HLT/8xLUWbUkTLc8M7XoPihgJshO5H871IUrF+UI6UchlJc81t8BDfF6G+2fSA wds9bJkdIJKndt1ISyHd1UGd37dQzq/3Wuffrz8kLM+YCu2qAQ4fidkU0l2oMC0wRMfS BkGS46F7hUInJKmnQTN13G/FcRR6NOa7R3fHiQ2zOdTPy00G7edjNopRJzccBFLxJ23t x/NnMuykXCNBDPu2KxEKhWxuZh2mEg+rB+igMCdzuRv4WqwaFukRLfCNqOKYaSlQBHBV eYPniPvLBJWdnsN+l89c+hrv50kRxc5COanLzJaUCbUq/lKetJhgyQ90/iho1QPJ2jZ9 2Jqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=kaai28x9FG9xqqC3zpoCF0gZijWD/V2hk7A8DunPxfw=; b=IjNZUMrv9lAWe+82ry62gBZXstmjTxGN78tgNDhNCQvfLWUtoS41Ys1w4Y6o+lru5g Bqd7A1ufmLo+BrlP8EjxxriI7ybVoM8VQ7/t1BrCR8jKiz83fTYibzhW6I+wwM8D2+Wo 3WpbrbsK7QzKm3c/wmn6rF/4yOym6ULshpOqbZmmhqsYKrO8uDCjBmtvybPTWX4ATcmf rF5+cBuuohpME4A7DpXvz7FxLHM5SrA/zj9andgTNsxDNcoy0fzYRcbT6yYgyJEEz87t OOf1QtXdhizF3TaPgDD1jxq3dFWhixf28be6Qiu3z8zAJ2+nRLVJblh5WNfkplp54UbH vLmA== X-Gm-Message-State: AJcUukdivEraDPfI/o4OHbIJYZZjnRnLHBeN2WGswsyqySn/XpMMwRgC /rx+i3yGhPXGjcjxhkOhPkKG+LieDHLPSw/Se3E= X-Google-Smtp-Source: ALg8bN4m0H7v4KFSw+a/+GqvTsdbN/0p/LNKQX60cmnZeeaffpOeIMG7cDU9Hq0PoVyfNyAItYEDaplXQxVLjuS7PKo= X-Received: by 2002:a9f:314c:: with SMTP id n12mr984734uab.33.1548255211654; Wed, 23 Jan 2019 06:53:31 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 23 Jan 2019 15:53:18 +0100 Message-ID: To: Claude Pache Cc: Arvids Godjuks , Jani Ollikainen , "internals@lists.php.net" Content-Type: multipart/alternative; boundary="000000000000e992ae05802141ed" Subject: Re: [PHP-DEV] Deprecation ideas for PHP 8 From: george.banyard@gmail.com (Girgias) --000000000000e992ae05802141ed Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, 23 Jan 2019 at 15:43, Claude Pache wrote: > So, since you didn=E2=80=99t see, here are some practical usages of setty= pe(): > > function foo($bar) { > // $bar is supposed to be either a string, or a list of strings > settype($bar, 'array'); > // ... > } > > function qux($id) { > if (!(is_int($id) || is_string($id) && ctype_digit($id))) > throw new \TypeError; > settype($id, 'int'); > // ... > } > > class Foo implements SeekableIterator { > function seek(/* int */ $position): void { > // NOTE: we cannot use int typehint here, because PHP7.1 requires > mixed > settype($position, 'int'); > // ... > } > } > ?> > All these examples could very well use a typecast and or one of the *val functions > Here are a usage of settype() with a non-constant second parameter: Defin= e > a utility function that cast a value to a given type when it is not null: > > function cast_opt($val, $type) { > if ($val !=3D=3D null) > settype($val, $type); > return $val; > } > > $foo =3D cast_opt($bar, 'int') // equivalent to: $foo =3D $bar =3D=3D=3D = null ? null > : (int) $bar; > ?> > > Sure, one can avoid settype() and do it the complicated way, but why? Wha= t > is the issue with settype(), so that you want to deprecate it? > You didn't necessarely need to specify an example with a non-constant second parameter because you already gave valid arguments as why not to deprecate it, just that I didn't see them. I do appreciate the example however. Why I want*ed* to deprecate is because I personally didn't see any usage before, you provided a valid usage and I don't see the point of deprecating it anymore. Maybe that wasn't clear from my previous reply. Because indeed removing settype brings back the same issue that I raised with gettype. As it currently stands the only way I can see how settype can possibly be deprecated is ih PHP introduces a ReflectionVar classe which, like said in my initial email, seems like total overkill when a simple function exists. Hope this clears everything up Best regards George P. Banyard --000000000000e992ae05802141ed--