[Binari] PHP pass by reference problem

Hi, with the introduction of magic methods in php5, you could have a catch-all function called __call($function, $args) to kick in as soon as no matching function was found for a call. This is great, as I can write one baseclass with default functionality. Secondly, in the main program I had something like this: $q = start_event_queue(); $result1 = $q->push(an_event); $result2 = $q->push(another_event); ... $q->fire_events(); The $result# where references to the actual results, so they didn't get a relevant value before fire_events is fired. This is great too. Thirdly, I wrapped above functionality so the events don't have to be defined .. even at runtime (yeah yeah, don't trip on this one ..). So I use the magic method __call to catch these. And here comes the problem... The magic method __call doesn't return by reference! (ARGG!) There's even a 4 year old bug report about it: http://bugs.php.net/bug.php?id=30959&edit=1 Does anyone have an idea how I could automagically remove that extra level, or how I could administer the perfect solution illustrated in 'secondly'. So, the question is: what the easiest way to administer this problem. -Kenny ps: djeezes, what an explanation. pps: the Francis/Stephane solution: "Actually, we need to rewrite php to basicly fit perl better" -- ================================================================== Kenny Billiau Web Developer Tel:+32 (0)9 331 36 95 fax:+32 (0)9 3313809 VIB Department of Plant Systems Biology, Ghent University Technologiepark 927, 9052 Gent, BELGIUM kenny.billiau@ugent.be http://bioinformatics.psb.ugent.be ================================================================== "The price good men pay for indifference to public affairs is to be ruled by evil men." -Plato

WTF are you trying to do? Usually if you see more than one time "magic" or "automagically" in the description of a piece of software, you known you're in trouble. Especially in combination with catch all+wrappers that allow you to leave stuff undefined. Do you even expect this to work? Sorry, no solution ;-) Kenny Billiau wrote:
Hi,
with the introduction of magic methods in php5, you could have a catch-all function called __call($function, $args) to kick in as soon as no matching function was found for a call. This is great, as I can write one baseclass with default functionality.
Secondly, in the main program I had something like this:
$q = start_event_queue(); $result1 = $q->push(an_event); $result2 = $q->push(another_event); ... $q->fire_events();
The $result# where references to the actual results, so they didn't get a relevant value before fire_events is fired. This is great too.
Thirdly, I wrapped above functionality so the events don't have to be defined .. even at runtime (yeah yeah, don't trip on this one ..). So I use the magic method __call to catch these. And here comes the problem...
The magic method __call doesn't return by reference! (ARGG!) There's even a 4 year old bug report about it: http://bugs.php.net/bug.php?id=30959&edit=1 Does anyone have an idea how I could automagically remove that extra level, or how I could administer the perfect solution illustrated in 'secondly'.
So, the question is: what the easiest way to administer this problem.
-Kenny ps: djeezes, what an explanation. pps: the Francis/Stephane solution: "Actually, we need to rewrite php to basicly fit perl better"

I'm not gonna describe what I'm doing (it's not the scope of the post ;)) (unless you really want to know of course.) (but I think it suffices to tell you I'm doing it so Lieven doesn't have to do a lot of work ;)) But a possible solution would be to wrap the return of __call into an array, which gets passed by value, thus copying the reference of the result with it ;) The problem is then that the returned result is .. well .. wrapped in an array ;) (maybe I can write another __call to remove this ? ;)) [release] => Array ( --==> [0] => Array <==-- this level is unnecessary! ( [Picpa] => Array ( [release] => 666666 [start_locus] => chr1-1_0002 ) ) ) Kenny ps: maybe I'm just nitpicking here .. ;) pps: ok, this is what I'm doing: cakePHP handles database access gracefully. You can ask things to your table (model) like "find('all', 'matching these conditions')". Now, I simply made sure that, if you ask a question (function) to a model, and the function doesn't exists, it get's forwarded to the webservice .. This makes for a transparent use of models on the website. (I don't have to make a difference between what is in cake and what is in perl). (You see why I want to have it in 1 goddamn technology?) On Tue, 3 Feb 2009, Thomas Abeel wrote:
WTF are you trying to do?
Usually if you see more than one time "magic" or "automagically" in the description of a piece of software, you known you're in trouble. Especially in combination with catch all+wrappers that allow you to leave stuff undefined. Do you even expect this to work?
Sorry, no solution ;-)
Kenny Billiau wrote:
Hi,
with the introduction of magic methods in php5, you could have a catch-all function called __call($function, $args) to kick in as soon as no matching function was found for a call. This is great, as I can write one baseclass with default functionality.
Secondly, in the main program I had something like this:
$q = start_event_queue(); $result1 = $q->push(an_event); $result2 = $q->push(another_event); ... $q->fire_events();
The $result# where references to the actual results, so they didn't get a relevant value before fire_events is fired. This is great too.
Thirdly, I wrapped above functionality so the events don't have to be defined .. even at runtime (yeah yeah, don't trip on this one ..). So I use the magic method __call to catch these. And here comes the problem...
The magic method __call doesn't return by reference! (ARGG!) There's even a 4 year old bug report about it: http://bugs.php.net/bug.php?id=30959&edit=1 Does anyone have an idea how I could automagically remove that extra level, or how I could administer the perfect solution illustrated in 'secondly'.
So, the question is: what the easiest way to administer this problem.
-Kenny ps: djeezes, what an explanation. pps: the Francis/Stephane solution: "Actually, we need to rewrite php to basicly fit perl better"
-- ================================================================== Kenny Billiau Web Developer Tel:+32 (0)9 331 36 95 fax:+32 (0)9 3313809 VIB Department of Plant Systems Biology, Ghent University Technologiepark 927, 9052 Gent, BELGIUM kenny.billiau@ugent.be http://bioinformatics.psb.ugent.be ================================================================== "The price good men pay for indifference to public affairs is to be ruled by evil men." -Plato

Cant you give the reference of the variable which should contain the result for the function-to-be-called as an argument, when calling the function? So, you call function foo like this : foo (& $bar){}, and then you get __call($foo,&$bar){} If you then set the variable of $bar in the __call routine, then you dont need to bother with the possible result of the __call function. Or am i missing something? Kenny Billiau wrote:
I'm not gonna describe what I'm doing (it's not the scope of the post ;)) (unless you really want to know of course.) (but I think it suffices to tell you I'm doing it so Lieven doesn't have to do a lot of work ;))
But a possible solution would be to wrap the return of __call into an array, which gets passed by value, thus copying the reference of the result with it ;) The problem is then that the returned result is .. well .. wrapped in an array ;) (maybe I can write another __call to remove this ? ;))
[release] => Array ( --==> [0] => Array <==-- this level is unnecessary! ( [Picpa] => Array ( [release] => 666666 [start_locus] => chr1-1_0002 )
)
)
Kenny ps: maybe I'm just nitpicking here .. ;) pps: ok, this is what I'm doing: cakePHP handles database access gracefully. You can ask things to your table (model) like "find('all', 'matching these conditions')". Now, I simply made sure that, if you ask a question (function) to a model, and the function doesn't exists, it get's forwarded to the webservice .. This makes for a transparent use of models on the website. (I don't have to make a difference between what is in cake and what is in perl). (You see why I want to have it in 1 goddamn technology?)
On Tue, 3 Feb 2009, Thomas Abeel wrote:
WTF are you trying to do?
Usually if you see more than one time "magic" or "automagically" in the description of a piece of software, you known you're in trouble. Especially in combination with catch all+wrappers that allow you to leave stuff undefined. Do you even expect this to work?
Sorry, no solution ;-)
Kenny Billiau wrote:
Hi,
with the introduction of magic methods in php5, you could have a catch-all function called __call($function, $args) to kick in as soon as no matching function was found for a call. This is great, as I can write one baseclass with default functionality.
Secondly, in the main program I had something like this:
$q = start_event_queue(); $result1 = $q->push(an_event); $result2 = $q->push(another_event); ... $q->fire_events();
The $result# where references to the actual results, so they didn't get a relevant value before fire_events is fired. This is great too.
Thirdly, I wrapped above functionality so the events don't have to be defined .. even at runtime (yeah yeah, don't trip on this one ..). So I use the magic method __call to catch these. And here comes the problem...
The magic method __call doesn't return by reference! (ARGG!) There's even a 4 year old bug report about it: http://bugs.php.net/bug.php?id=30959&edit=1 Does anyone have an idea how I could automagically remove that extra level, or how I could administer the perfect solution illustrated in 'secondly'.
So, the question is: what the easiest way to administer this problem.
-Kenny ps: djeezes, what an explanation. pps: the Francis/Stephane solution: "Actually, we need to rewrite php to basicly fit perl better"
-- ================================================================== Michiel Van Bel PhD student Tel:+32 (0)9 331 36 95 fax:+32 (0)9 3313809 VIB Department of Plant Systems Biology, Ghent University Technologiepark 927, 9052 Gent, BELGIUM mibel@psb.vib-ugent.be http://www.psb.vib-ugent.be ==================================================================

Ah, yes I can! On Tue, 3 Feb 2009, Michiel Van Bel wrote:
Cant you give the reference of the variable which should contain the result for the function-to-be-called as an argument, when calling the function?
So, you call function foo like this : foo (& $bar){}, and then you get __call($foo,&$bar){} If you then set the variable of $bar in the __call routine, then you dont need to bother with the possible result of the __call function.
Or am i missing something?
Kenny Billiau wrote:
I'm not gonna describe what I'm doing (it's not the scope of the post ;)) (unless you really want to know of course.) (but I think it suffices to tell you I'm doing it so Lieven doesn't have to do a lot of work ;))
But a possible solution would be to wrap the return of __call into an array, which gets passed by value, thus copying the reference of the result with it ;) The problem is then that the returned result is .. well .. wrapped in an array ;) (maybe I can write another __call to remove this ? ;))
[release] => Array ( --==> [0] => Array <==-- this level is unnecessary! ( [Picpa] => Array ( [release] => 666666 [start_locus] => chr1-1_0002 )
)
)
Kenny ps: maybe I'm just nitpicking here .. ;) pps: ok, this is what I'm doing: cakePHP handles database access gracefully. You can ask things to your table (model) like "find('all', 'matching these conditions')". Now, I simply made sure that, if you ask a question (function) to a model, and the function doesn't exists, it get's forwarded to the webservice .. This makes for a transparent use of models on the website. (I don't have to make a difference between what is in cake and what is in perl). (You see why I want to have it in 1 goddamn technology?)
On Tue, 3 Feb 2009, Thomas Abeel wrote:
WTF are you trying to do?
Usually if you see more than one time "magic" or "automagically" in the description of a piece of software, you known you're in trouble. Especially in combination with catch all+wrappers that allow you to leave stuff undefined. Do you even expect this to work?
Sorry, no solution ;-)
Kenny Billiau wrote:
Hi,
with the introduction of magic methods in php5, you could have a catch-all function called __call($function, $args) to kick in as soon as no matching function was found for a call. This is great, as I can write one baseclass with default functionality.
Secondly, in the main program I had something like this:
$q = start_event_queue(); $result1 = $q->push(an_event); $result2 = $q->push(another_event); ... $q->fire_events();
The $result# where references to the actual results, so they didn't get a relevant value before fire_events is fired. This is great too.
Thirdly, I wrapped above functionality so the events don't have to be defined .. even at runtime (yeah yeah, don't trip on this one ..). So I use the magic method __call to catch these. And here comes the problem...
The magic method __call doesn't return by reference! (ARGG!) There's even a 4 year old bug report about it: http://bugs.php.net/bug.php?id=30959&edit=1 Does anyone have an idea how I could automagically remove that extra level, or how I could administer the perfect solution illustrated in 'secondly'.
So, the question is: what the easiest way to administer this problem.
-Kenny ps: djeezes, what an explanation. pps: the Francis/Stephane solution: "Actually, we need to rewrite php to basicly fit perl better"
-- ================================================================== Kenny Billiau Web Developer Tel:+32 (0)9 331 36 95 fax:+32 (0)9 3313809 VIB Department of Plant Systems Biology, Ghent University Technologiepark 927, 9052 Gent, BELGIUM kenny.billiau@ugent.be http://bioinformatics.psb.ugent.be ================================================================== "The price good men pay for indifference to public affairs is to be ruled by evil men." -Plato

The solution is actually simple: don't use __call and make your own model interface so you can do things like: $q->start_queue(); result1 =& $q->push('functionname', $param, $param, ..); result2 =& $q->push('functionname', $param, $param, ..); ... $q->fire_events(); instead of $result1 =& $q->functionname($param, $param, ...); I mean .. now it's just about estaetics :) (with the added bonus you actually see that you push onto a queue ;)) -Kenny ps: so yeah, it seems you're right when saying that too much magic leads to a troubled reality.. On Tue, 3 Feb 2009, Kenny Billiau wrote:
I'm not gonna describe what I'm doing (it's not the scope of the post ;)) (unless you really want to know of course.) (but I think it suffices to tell you I'm doing it so Lieven doesn't have to do a lot of work ;))
But a possible solution would be to wrap the return of __call into an array, which gets passed by value, thus copying the reference of the result with it ;) The problem is then that the returned result is .. well .. wrapped in an array ;) (maybe I can write another __call to remove this ? ;))
[release] => Array ( --==> [0] => Array <==-- this level is unnecessary! ( [Picpa] => Array ( [release] => 666666 [start_locus] => chr1-1_0002 )
)
)
Kenny ps: maybe I'm just nitpicking here .. ;) pps: ok, this is what I'm doing: cakePHP handles database access gracefully. You can ask things to your table (model) like "find('all', 'matching these conditions')". Now, I simply made sure that, if you ask a question (function) to a model, and the function doesn't exists, it get's forwarded to the webservice .. This makes for a transparent use of models on the website. (I don't have to make a difference between what is in cake and what is in perl). (You see why I want to have it in 1 goddamn technology?)
On Tue, 3 Feb 2009, Thomas Abeel wrote:
WTF are you trying to do?
Usually if you see more than one time "magic" or "automagically" in the description of a piece of software, you known you're in trouble. Especially in combination with catch all+wrappers that allow you to leave stuff undefined. Do you even expect this to work?
Sorry, no solution ;-)
Kenny Billiau wrote:
Hi,
with the introduction of magic methods in php5, you could have a catch-all function called __call($function, $args) to kick in as soon as no matching function was found for a call. This is great, as I can write one baseclass with default functionality.
Secondly, in the main program I had something like this:
$q = start_event_queue(); $result1 = $q->push(an_event); $result2 = $q->push(another_event); ... $q->fire_events();
The $result# where references to the actual results, so they didn't get a relevant value before fire_events is fired. This is great too.
Thirdly, I wrapped above functionality so the events don't have to be defined .. even at runtime (yeah yeah, don't trip on this one ..). So I use the magic method __call to catch these. And here comes the problem...
The magic method __call doesn't return by reference! (ARGG!) There's even a 4 year old bug report about it: http://bugs.php.net/bug.php?id=30959&edit=1 Does anyone have an idea how I could automagically remove that extra level, or how I could administer the perfect solution illustrated in 'secondly'.
So, the question is: what the easiest way to administer this problem.
-Kenny ps: djeezes, what an explanation. pps: the Francis/Stephane solution: "Actually, we need to rewrite php to basicly fit perl better"
-- ================================================================== Kenny Billiau Web Developer Tel:+32 (0)9 331 36 95 fax:+32 (0)9 3313809 VIB Department of Plant Systems Biology, Ghent University Technologiepark 927, 9052 Gent, BELGIUM kenny.billiau@ugent.be http://bioinformatics.psb.ugent.be ================================================================== "The price good men pay for indifference to public affairs is to be ruled by evil men." -Plato
participants (3)
-
Kenny Billiau
-
Michiel Van Bel
-
Thomas Abeel