Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94967 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94908 invoked from network); 9 Aug 2016 13:50:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Aug 2016 13:50:10 -0000 Authentication-Results: pb1.pair.com smtp.mail=david.proweb@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=david.proweb@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.173 as permitted sender) X-PHP-List-Original-Sender: david.proweb@gmail.com X-Host-Fingerprint: 209.85.216.173 mail-qt0-f173.google.com Received: from [209.85.216.173] ([209.85.216.173:34536] helo=mail-qt0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 31/C2-03404-19FD9A75 for ; Tue, 09 Aug 2016 09:50:09 -0400 Received: by mail-qt0-f173.google.com with SMTP id u25so5764901qtb.1 for ; Tue, 09 Aug 2016 06:50:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to; bh=xF+LaKujVLohs+pmlnI4VmgXaL5tLGX4qavZsaE/1Zw=; b=Br6RjBEqPV+KMbIRu+sTw7zv5czvz0cwmQHl7Einc18qWpodPyMInfxM18AlC2IuXE dK74kOaBfAxRDZZWTCL+DdsSt0DN513QmTpnrc0YG4DNihi7nAgbq+i3dmPF9UVQK2cA xL+JWDvANX8APyfT8Mu4wQRiXHgLUi/ZhYhwk6MGC9C6p+HFiDMIQjpT0Lf4n6PNcQOm gWRI9Wz1YqvBCCgZmD/GzM9d6SAyllZnVhkpjnWH/8cKwONi40LiamiA9XmPeaEfizve rvza0J4Agd+a2wKVTVnLkBQTqJuejU6BQOyt/bPcn4uIelzr5ikm79JluUq1L74Ro3fo Hsqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=xF+LaKujVLohs+pmlnI4VmgXaL5tLGX4qavZsaE/1Zw=; b=VvczNFaSJaStg9yArHpPVnbRZDWUtKyc8kvBJ2Tly2kcxOQbCmDpLBDxZvX0KLltMb QVXJ3x0kCrDZfiPjXUyHg+vwohHCdId/Oo9ATYmuqQEsJo6KgNt3DpvyHawCzYIY74l0 sFgsk3FrznSxlhWV0914uUSSnqK5FiDYiBIx3bh1ngFXC3e5+vF3QWgZAycSIVfCi1eI 8qMcTzdEymClo22uZDMaKAm2t+8Wf8bafdZHym5BjSUMdan0kFsbanwQH33w7NwYsixN SzPuTm183H1sb++x3KAwnDoKZ3LIjik1lUISxvzY/TIbChdX+iKz5lxf3wxJ3ORqHfsF JTdw== X-Gm-Message-State: AEkoout/N0szZRz/5xRlI2sUYB7vZyqZZLriHJ3z+mJdgV+zibYOpG3WzVQUHW6mSQ0m5ZH4JTTUZOPxe5PwaA== X-Received: by 10.237.55.65 with SMTP id i59mr35391333qtb.62.1470750606986; Tue, 09 Aug 2016 06:50:06 -0700 (PDT) MIME-Version: 1.0 Received: by 10.55.45.67 with HTTP; Tue, 9 Aug 2016 06:49:46 -0700 (PDT) Date: Tue, 9 Aug 2016 10:49:46 -0300 Message-ID: To: PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Treats raw types if used as object From: david.proweb@gmail.com (David Rodrigues) I and a friend are thinking about PHP to treats raw types as objects. Currently we have some raw types on PHP, like strings, ints, arrays, etc. Generally we should use some procedural functions to works with this types, for instance, strtolower(string). It works in general, but the most of languages treats this types as objects. JS, for instance, you should do String.toLower(). We can pass this string to a constructor to allow we treat it as object. But it should overload PHP if we do it with all raw types that we have. We have some Spl that do exactly that for array, for instance, but we should use with caution. In this case, I suggests to have some handler to treat raw types as objects in an indirect way. Objects are not created, but it methods are called on demand statically. For instance: // It should be declared by PHP internally (default handler). register_type_handler('string', \SplString::class); // It is an user defined handler, should extends SplInteger. register_type_handler('int', \Types\MyInt::class); class MyInt extends \SplInt { public static function max($max) { // $this is the own int return max($this - 1, $max); } } // Let's use: echo $string->lower(); // native defined function echo $int->max(5); // user defined function echo $int->min(2); // native defined function I think that it should not create any BC and not implements any new operator. Performance should be not affected, once it should be triggered only when type is called as object, and it should implements the same function implemented in procedural version. Should affects performance only if you have a user-defined method, because it will be done by PHP, not internally. The major advantage, in this case, is that you can works with OO over raw types and fixes the old PHP issue about function naming (no more str_ vs str). It too should avoid the matroska, by allowing call chained by default: $string->lower()->ucfirst(). There are someone that could write some code over PHP code to test the viability and performance? It should be great. In all case, depending of response here, I could try do something, but I don't promises. -- David Rodrigues