Re: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-21 Thread Jochem Maas
Michael Sims wrote: Jochem Maas wrote: Michael Sims wrote: So, as far as foo() knows: foo($a = 5); and foo(5); are exactly the same... I don't think they are, and you're examples don't prove it. Anyone care to come up with the proof. No, I was wrong, Rasmus corrected me. That's my on

RE: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-20 Thread Murray @ PlanetThoughtful
> Jochem Maas wrote: > > Michael Sims wrote: > >> So, as far as foo() knows: > >> > >> foo($a = 5); > >> and > >> foo(5); > >> > >> are exactly the same... > > > > I don't think they are, and you're examples don't prove it. > > Anyone care to come up with the proof. > > No, I was wrong, Rasmus cor

RE: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-20 Thread Michael Sims
Jochem Maas wrote: > Michael Sims wrote: >> So, as far as foo() knows: >> >> foo($a = 5); >> and >> foo(5); >> >> are exactly the same... > > I don't think they are, and you're examples don't prove it. > Anyone care to come up with the proof. No, I was wrong, Rasmus corrected me. That's my on

Re: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-20 Thread Jochem Maas
Michael Sims wrote: Jochem Maas wrote: foo($a = 5); by definition the expression is evaluated _before_ the function is called - so the expression is not passed to the function, the result of the expression is passed ... I was under the impression that the the expression evaluates to a 'pointe

RE: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-20 Thread Michael Sims
Rasmus Lerdorf wrote: > Michael Sims wrote: >> When used as an expression, an assignment evaluates to whatever is >> on the right side of the assignment operator, not the left. >> Example: [...] >> foo($a = 5); >> and >> foo(5); >> >> are exactly the same... > > The value passed is the same, b

Re: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-20 Thread Rasmus Lerdorf
Michael Sims wrote: > Jochem Maas wrote: > foo($a = 5); >> >>by definition the expression is evaluated _before_ the function is >>called - so the expression is not passed to the function, the result >>of the expression is passed ... I was under the impression that the >>the expression evaluate

Re: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-20 Thread Rasmus Lerdorf
Lester Caine wrote: > This type of code is used in a few places, so I'd like a little help > converting it to 'good code' under the new rules ;) > > Get the key from an array ( fails because key(&array) ) > > if( $pId == key( $this->getFunc() ) ) { > > In getFunc() > > return ( $this->g

Re: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-20 Thread Jochem Maas
thanks everyone for the crash course in better understanding the underlying mechanisms! ... I'm probably not the only one that learnt something from this ;-) Dragan Stanojevic - Nevidljivi wrote: Jochem Maas wrote: Basically, in PHP, a reference (such as what key() takes as a parameter [1]) c

Re: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-20 Thread Dragan Stanojevic - Nevidljivi
Jochem Maas wrote: Basically, in PHP, a reference (such as what key() takes as a parameter [1]) can only point to an actual variable, not directly to the result of a function. So you have to assign the output of the function to a variable first. wtf, Im now officially confused (before I suffer

RE: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-20 Thread Michael Sims
Jochem Maas wrote: >>> foo($a = 5); > > by definition the expression is evaluated _before_ the function is > called - so the expression is not passed to the function, the result > of the expression is passed ... I was under the impression that the > the expression evaluates to a 'pointer' (I'm sur

Re: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-20 Thread Jochem Maas
Jasper Bryant-Greene wrote: Jochem Maas wrote: Jasper Bryant-Greene wrote: From the PHP manual [2]: | the following examples of passing by reference are invalid: | | foo(bar()); // Produces fatal error since PHP 5.1.0 | foo($a = 5); // Expression, not variable if foo() expects one args by

Re: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-20 Thread Jasper Bryant-Greene
Jochem Maas wrote: Jasper Bryant-Greene wrote: From the PHP manual [2]: | the following examples of passing by reference are invalid: | | foo(bar()); // Produces fatal error since PHP 5.1.0 | foo($a = 5); // Expression, not variable if foo() expects one args by reference then why is doing: f

Re: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-20 Thread Jochem Maas
Jasper Bryant-Greene wrote: Lester Caine wrote: I suppose the REAL questions was - "Why was using the function in this way a 'bad practice', is there any way that it could be made a 'good practice' since the intent is so obvious?" I understand the new checks, but I don't see that the original

Re: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-20 Thread Jasper Bryant-Greene
Lester Caine wrote: I suppose the REAL questions was - "Why was using the function in this way a 'bad practice', is there any way that it could be made a 'good practice' since the intent is so obvious?" I understand the new checks, but I don't see that the original was particularly 'bad' - only

Re: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-20 Thread Lester Caine
Jasper Bryant-Greene wrote: Lester Caine wrote: This type of code is used in a few places, so I'd like a little help converting it to 'good code' under the new rules ;) They're not "new rules". PHP is just warning you where it didn't before. It was still bad coding practice before. Since

Re: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-20 Thread Jasper Bryant-Greene
Lester Caine wrote: This type of code is used in a few places, so I'd like a little help converting it to 'good code' under the new rules ;) They're not "new rules". PHP is just warning you where it didn't before. It was still bad coding practice before. Get the key from an array ( fails b