Robert Cummings wrote: > On Fri, 2005-09-16 at 10:28, Rasmus Lerdorf wrote: > >>Stephen Leaf wrote: >> >>>$this->urlArr[0] = array_pop($arr = explode("&",$this->urlArr[0])); >>> >>>I still have to scratch my head as to why I *need* that "$arr = " >>>prior to 5.0.5 this was not needed. >>>$this->urlArr[0] = array_pop(explode("&",$this->urlArr[0])); >> >>This is a much misunderstood issue. And we are still contemplating the >>best way to handle this. Let's take a step back to a really simple example: >> >> function foo() { >> return 3; >> } >> function bar(&$arg) { >> $arg = "banana"; >> } >> bar(foo()); >> >>What do we do with code like this? If you follow it through it is >>essentially doing: >> >> 3 = "banana"; >> >>which makes very little sense and is probably something the developer >>would want to know about. > > > I think this is part of the problem. While I understand how you got > > 3 = "banana" > > I don't agree with your position that the above code is incorrect, > rather I think there is a philosophical difference between some > developers as to what should be expected. Most programmers (I would > argue :), including myself say, Foo returns 3, the return value is > stored in a temporary container, the temporary container is then fed > into bar() which just happens to want a reference, so fine, it gets a > reference to a temporary container, then it sets the value to "banana". > So finally we get back out to the bar(foo()) calling scope and we > receive the temporary container. In which case the way people are using > these functions and references are perfectly valid and passing temporary > return containers to reference expecting functions is not necessarily a > bug, but a philosophical question of understanding what the hell you're > doing :) Well, this is the sort of thing the language should help you with. Whether or not the code is incorrect or not is not the relevant question I think. The question is whether the language should try to detect when you are doing something that is not going to do what you expect. If someone really writes code like the above, I see it as a plus if they could get an optional warning about it. That's exactly what an E_NOTICE on this is for. > As you are seeing now, we now have a horrible situation where > the developer now has to care about whether they are passing a value to > a function expecting a reference or not, and if that function expects a > reference they now have to manually create a temporary container > themselves :/ Anyways, I've already accepted whatever comes out of all > this, but personally I don't think the code you showed above is wrong at > all :) Well, you can turn off notices, or rather not turn them on since they are off by default, and you won't have to care. Like I said, the current fatal error in 5.0.5 on this is incorrect and we will fix that, but I still believe it is a good idea to provide users with a way to get warnings on cases where references are dropped since it could very well hide a bug in their code. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php