php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #57723 Allow __call intercept overload magic
Submitted: 2007-06-27 10:40 UTC Modified: 2017-10-24 23:02 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: vinyanov at poczta dot onet dot pl Assigned:
Status: Suspended Package: operator (PECL)
PHP Version: 5.2.0 OS: Windows XP
Private report: No CVE-ID: None
 [2007-06-27 10:40 UTC] vinyanov at poczta dot onet dot pl
Description:
------------
Hello,

I love the extension. :) However, could __call possibly catch requests for non-declared overload methods? It would:

* Help maintain the code brief
* Consist with call_user_func behaviour
* Say we overload methods within a class hierarchy and result of the overload yields an object of the original class. Cumulation of logic inside __call would save repeating the similar routine in each method:

// calculating effect of the overload
$class = get_class();
return new $class($result);

Reproduce code:
---------------
class Person
{
	function __call($meth, $args)
	{
		switch(substr($meth, 2))
		{
			case 'add':	return 'Couple';
			case 'sub':	return 'Part';
		}
	}
}

$john = new Person;
echo $john + 1;

Expected result:
----------------
Couple

Actual result:
--------------
Notice: Object of class Person could not be converted to int in C:\www\main\phppm\test.php on line 16
2

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-29 13:10 UTC] pollita@php.net
Sure, that's certainly feasible.... I'll see what I can do, no promises on when though...
 [2017-10-24 06:23 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: pollita +Assigned To:
 [2017-10-24 23:01 UTC] kalle@php.net
-Package: operator +Package: Scripting Engine problem
 [2017-10-24 23:02 UTC] kalle@php.net
-Status: Open +Status: Suspended -Package: Scripting Engine problem +Package: operator
 [2017-10-24 23:02 UTC] kalle@php.net
The operator PECL package have not had a release for 4 years and development activity seems to have ceased, if a new maintainer picks up this package, then this report should be re-opened
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 07 14:01:28 2024 UTC