Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82892 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44454 invoked from network); 16 Feb 2015 22:00:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Feb 2015 22:00:45 -0000 Authentication-Results: pb1.pair.com header.from=pajousek@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=pajousek@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.54 as permitted sender) X-PHP-List-Original-Sender: pajousek@gmail.com X-Host-Fingerprint: 209.85.192.54 mail-qg0-f54.google.com Received: from [209.85.192.54] ([209.85.192.54:41969] helo=mail-qg0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6E/D0-36518-D8862E45 for ; Mon, 16 Feb 2015 17:00:45 -0500 Received: by mail-qg0-f54.google.com with SMTP id z60so25304601qgd.13 for ; Mon, 16 Feb 2015 14:00:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=mdPzK3jKv5zrgdxzgLSzziCtfjf/4ISNCZ/EaS8rXHY=; b=RhyhXj3RYizR/uqnaEjKn+EUWxM8APxf1l84lI8iDCx1FX7JVMBWIJ91grmHZVVV35 Yu9z9L+k7fGacv5JJkQe3ze+OYSXSeROywjWLhJ+uFQdIU0w1hsFW/VbqMVKliZHEwJf OESUBQryknjpVWkb/Ex+i5OWVeLNFARuXxOjIcC59MfcMy925nkqlDFrkX5Nrt8JoUAz PHmFa7MfCjMiZA5g7U8bG8msOEitblKll+aAJ1MDzjm/YK+bCtJiyzQ3MI3USso3r5mH g/uIJN7nIcfngw0gPQ/BK5FMrw7TF+BMsJRxt3juMUWmd8sji85Bf1diOmilc75G9GF7 WyYw== MIME-Version: 1.0 X-Received: by 10.140.231.151 with SMTP id b145mr1503523qhc.22.1424124042544; Mon, 16 Feb 2015 14:00:42 -0800 (PST) Received: by 10.96.66.201 with HTTP; Mon, 16 Feb 2015 14:00:42 -0800 (PST) In-Reply-To: <015a01d04a2a$329ce7d0$97d6b770$@php.net> References: <011801d04a07$83ab1c00$8b015400$@php.net> <015a01d04a2a$329ce7d0$97d6b770$@php.net> Date: Mon, 16 Feb 2015 23:00:42 +0100 Message-ID: To: francois@php.net Cc: Arvids Godjuks , Jefferson Gonzalez , Rowan Collins , PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Reviving scalar type hints From: pajousek@gmail.com (=?UTF-8?Q?Pavel_Kou=C5=99il?=) On Mon, Feb 16, 2015 at 9:50 PM, Fran=C3=A7ois Laupretre = wrote: >> De : Pavel Kouril [mailto:pajousek@gmail.com] >> >> Hello, >> >> I know this is probably a pretty unpopular opinion in PHP (based on >> the replies I got in the other thread), but different values for >> parameters should be IMHO solved by method overloading and such. > > The question is not that it's unpopular, it's that 1. It requires strict = types, and 2. If we want to solve this by polymorphism, we must also suppor= t polymorphism on functions. Now, tell me how you would solve the tan(int|f= loat) case with polymorphism ? One 'tan' function for int, one for float ? = str_replace(string|array, string|array, string|array, int &) is also a nice= case to study if you can't sleep... > > Sorry but polymorphism on scalar types is possible with strict types only= , which is out of scope for the next RFC. > > Fran=C3=A7ois > I will get to this more tomorrow, but now just a short notes: I'd only have tan(float) with int being able to be passed and the value would be implicitly converted to float. This is something even strongly typed languages normally do, and there is no reason PHP shouldn't be able to. If somebody would make a tan(float) and tan(int) declarations, then when calling tan($x), the apropriate one based on current type of $x should be called. I don't see any reason why this can be done only for strongly typed languages; could you name exact reasons? The str_replace(string|array $search, string|array $replace, string|array $subject[, int &$count ]) is a harder one to comment on though. I will refrain from answering on that one right now and will get back to that one tomorrow, because that one needs a little bit more thinking. Regards Pavel Kouril