#50969 [Bgs]: operator overloading for classes

From: Date: Mon, 08 Feb 2010 23:54:47 +0000
Subject: #50969 [Bgs]: operator overloading for classes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-147349@lists.php.net to get a copy of this message
ID: 50969 Updated by: johannes@php.net Reported By: sylvain at abstraction dot fr Status: Bogus Bug Type: Feature/Change Request Operating System: all PHP Version: 5.3.2RC1 New Comment: Well it is implemented, as you can see when following the link, I myself once created a patch to make it a bit nicer in syntax but it will never be implemented (as far as never goes) And well the issue, in the most simple form, is something like this: function foo() { return bar() + baz(); } In today's world during are view you can say "this will return a numeric value"with operator overloading you can say "this will return something or maybe fail" Becomes especially "funny" with return bar() + 4; Sure there's convention and comments and things but that won't help and you can always do return bar()->add(baz()); or return someclass::add(bar(), baz()); which makes the intention clear. Yes $a + $b + $c + $d might be bit nicer to read than the long form - but only as long as you know what types you have ... Previous Comments: ------------------------------------------------------------------------ [2010-02-08 23:15:17] sylvain at abstraction dot fr I'm not particularly aware of operator overloading in other language but I don't see why it would be less readable in PHP than in any other language as the only way to know what is happening is to read the code of the method overloading the operator. Anyhow, do I have to take as official PHP Team position that you won't implement it ? ------------------------------------------------------------------------ [2010-02-08 22:59:25] johannes@php.net Operator overloading in a dynamically weak typed language is bad as reading code gives no information what's happening. If you really want it go to http://pecl.php.net/operator maybe that still works. ------------------------------------------------------------------------ [2010-02-08 22:49:23] sylvain at abstraction dot fr Description: ------------ I would like to know what is the current PHP team position about operator overloading in PHP for classes. Operator overloading has been stated Bogus in http://bugs.php.net/bug.php?id=9331 but it was more than two years ago. I think it would be nice to have a discussion about that topic. If you recently had one I would be interested if you could indicate me where I can find it. Best Regards. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50969&edit=1

« previous php.bugs (#147349) next »