|
Posted by "Carl Furst" on 09/18/05 23:59
Chris,
You probably are aware that this comes from a C/C++ standard the '&' before
the variable means that you are passing by reference and not by value. If
you are passing by reference, you are passing the address of a variable
instead of the value of that variable.
By passing the value of 3 the script crashes because it thinks that you are
passing a pointer to address 3 in memory. This means the computer thinks
that the value being passed to the function is located in memory address '3'
which is invalid because that memory address is reserved for the OS (at
least on most machines the lowest memory addresses are reserved for the OS.)
In order to make your code work you would have to pass a variable so that
the computer can get the address of that variable and use/compute the data
located there.
Sounds like the original problem is some kind of type mismatch of this sort.
Carl
> -----Original Message-----
> From: Chris Shiflett [mailto:shiflett@php.net]
> Sent: Sunday, September 18, 2005 4:10 PM
> To: Robert Cummings
> Cc: Rasmus Lerdorf; Stephen Leaf; PHP-General
> Subject: Re: [PHP] Quick Poll: PHP 4 / 5
>
> Robert Cummings wrote:
> > I don't agree with your position that the above code is incorrect
>
> I think notices are fine for situations where you've probably screwed
> up. I'd rather PHP let me know than do nothing.
>
> I see this situation as being very similar to the following:
>
> <?php
>
> function foo(&$bar)
> {
> /* ... */
> }
>
> foo(3);
>
> ?>
>
> This happens to throw a fatal error, which seems fine (mainly because it
> always has, as far as I know, so no one can have working code that does
> this sort of thing).
>
> I'm curious to know whether you would also disagree that this code is
> incorrect. I don't see a big fundamental difference, but I might be
> misunderstanding something.
>
> Chris
>
> --
> Chris Shiflett
> Brain Bulb, The PHP Consultancy
> http://brainbulb.com/
Navigation:
[Reply to this message]
|