php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #33881 better "overloading"
Submitted: 2005-07-27 13:28 UTC Modified: 2005-07-28 09:28 UTC
From: robert dot sevcik at gmail dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: * OS: *
Private report: No CVE-ID: None
 [2005-07-27 13:28 UTC] robert dot sevcik at gmail dot com
Description:
------------
Actual state of "overloading", which in PHP5 means "dynamic way to work with object props and methods" is a bit frustrating.

I'd like to express my point of view if there is a chance to change... it is a whole philosophy may be for PHP 5.6 or at least PHP6

1) __get() __set() __call() methods should be called whenever they are present in class, not only if another member of suplied name exists. You can always decide within the method whether to use existing member or not.

2) there should be always a default in every class which can be overriden: providing access to existing members + working with setters and getters (getVar() xor get_var() style), true method overloading could be implemented in default as well (multiple method sign. with parameter type checking must be implemented, type spec for trivial types as well).

3) there should be a way to distinguish between public, protected and private ( func_get_access_type() ) and to chek which type members are ( class_get_member_access_type() )

4) it should work recursively and set/get together which (not working) i consider as a bug of current implementation

5) protos should be __get($name, & $value) __set($name, $value) __call($name, $args, & $returnValue) ; methods should return "Ok, handled", or "No, not handled" ; engine should try from child to parant classes to find which class accepted the call ; if none, raise an error.

6) there should be a way to document dynamic properties and methods - i know this is a litle OT - so it can be used for phpDoc, autocomplete and so on. (abstract properties syntax?) - yes now I see - that could be accomplished just by 1)

7) some introspection is needed what coheres with 7) for soap and similar specialities and for functions like serialize(), isset(), method_exists() ...... no idea how to... __get() __set() __call() could return list of handled members when called without args, or there could be a new function __tell() for this?

8) everything should work transparently the same way as static members do - this sums up 1-7 :)

... :) excuse my english pls :) happy PHPing


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-27 21:28 UTC] helly@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php

The existing functions cannot be changed in the way requested because that would be a major BC.

Introducing new magic functions makes no sense because we have already too much magic.

Furthermore adding a non magic way would slow down object execution far too much.

As a consequence the only possible ways out would be:

1) Go with interface ArrayAccess and use array notation instead of property notation.

2) Implement an extensions that implements objects that 
support this kind of thing.

3) Implement a new way of hooking based on interface like ArrayAccess but for properties.

Since we already support (1) we won't change anything simply because there is no need (thus Fixed in release).

In the end what we really need is real property implementation, where any decalred proeprty can specify whether it is a normal property, a property that can only store a certain king of instance and/or whether it is controlled by handler functions rather than by direct read/write access.
 [2005-07-28 09:28 UTC] robert dot sevcik at gmail dot com
Ok, I knew it would break BC, it was just an idea.

The last paragraph you wrote was interresting, when do you think it could be done?

My point 4 would be still nice, but that's another bug-report...

Thank you anyway :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 20:01:32 2024 UTC