Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89970 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76162 invoked from network); 3 Jan 2016 02:59:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jan 2016 02:59:46 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.53 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.220.53 mail-pa0-f53.google.com Received: from [209.85.220.53] ([209.85.220.53:35299] helo=mail-pa0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B8/23-33667-1AE88865 for ; Sat, 02 Jan 2016 21:59:46 -0500 Received: by mail-pa0-f53.google.com with SMTP id ho8so135826pac.2 for ; Sat, 02 Jan 2016 18:59:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=Xq8q715RVVD5zNsVg/Wo3ZYmup3Hw0w8rtGoPNB92nc=; b=Vs7PzzeLyzxGpGCSLrSZnopihNcAxdiMs6pDooCwjcilcGk5/HJWqPBZ3p9NBabMT7 PuXQyL975HOgY89Q81IB6aXEuYMhmfj/9ve23MMllkbNpfSivTT7cLz1I8nWaiUUc96H fbjFvCE7acJqdfedu93EqCL/TH0nT0Ve3j2RkABFIqlHbVjKfaSDroPtI8QVV7hqOl5q xD/9TrsF+0PJkrhe4JrQsQWEn6B2meYXgweTbehOD0KUAJwSrajlIdYZS2xYliRG2xSz ug51yKv54RFN4vtzJQlQdvjvi+vsY1edhhrf4sipqLish/fjOejEX6zBeAoyY09fwjhw +LDg== X-Received: by 10.66.139.166 with SMTP id qz6mr43131755pab.148.1451789982283; Sat, 02 Jan 2016 18:59:42 -0800 (PST) Received: from Stas-Air.local ([2602:304:cdc2:e5f0:554a:4543:337e:3b74]) by smtp.gmail.com with ESMTPSA id 7sm111631186pfb.62.2016.01.02.18.59.41 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 02 Jan 2016 18:59:41 -0800 (PST) To: Sara Golemon , PHP internals , patriciotarantino@gmail.com References: X-Enigmail-Draft-Status: N1110 Message-ID: <56888E9A.5020400@gmail.com> Date: Sat, 2 Jan 2016 18:59:38 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] RFC Operator Overloading in Userspace From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > Patricio Tarantino has asked me to help him propose Operator > Overloading in PHP 7.1 (based in part on my operator extension in > PECL). I think we can expose this to usespace as magic methods with > very little overhead (the runtime check and dispatch is already there, > after all). We could, but I'm not sure whether we should. One of the reasons why userspace operator overloading was kept out was that a lot of its uses make code worse, not better. When you see expression that looks like addition but you know it can do literally anything, that makes reading the code so much more frustrating. I mean, you can *hope* * still means "multiply", but you can't know it anymore. And there are not that many types for which * has natural meaning. Additionally, introducing about 9000^W^W a lot of new magics drastically raises both cognitive complexity of the language (now we have 14 magics, adding operators (and RFC lists only arithmetic ones, though one may say why stop there - C++ certainly didn't) more than triples that count. Also, implementing them in consistent fashion would be non-trivial, and imagine what fun would be had when +, += and ++ work differently (btw, why have different implementations for + and += at all?). And then we get questions of commutativity and associativity... What I'm trying to say, doing proper operators set is not that trivial, and besides a very small set of use cases, I'm concerned it would be used to write very clever write-once read-never code instead of good code. -- Stas Malyshev smalyshev@gmail.com