You are here: Re: multiple stacks, multiple versions bother anybody, or is it just me? « PHP Programming Language « IT news, forums, messages
Re: multiple stacks, multiple versions bother anybody, or is it just me?

Posted by Jerry Stuckle on 11/15/05 22:02

Oli Filth wrote:
> Jerry Stuckle said the following on 15/11/2005 17:09:
>
>> Rich Kucera wrote:
>>
>>> Why not? You never did this: $x = f1( f2( $y ) ); ?
>>>
>>> For example:
>>>
>>> $dir_path_component = array_pop( split('[/]',$dir) );
>>>
>>> This syntax seems second nature to me. It is now broken.
>>>
>>> You now have to inject a $foo variable into your syntax:
>>>
>>> $dir_path_component = array_pop( $foo = split('[/]',$dir) );
>>>
>>> Seems like other languages have solved whatever ill-effects result from
>>> passing of function results to another function.
>>>
>>
>> Sure - but not if f1() takes a reference. It works fine if f1() takes
>> a value.
>>
>> For instance, what is supposed to happen if you do something like:
>>
>> function f1 (&$i) {
>> $i++;
>> }
>>
>> Java and C++ handle this by not allowing a temporary to be passed as a
>> reference (compiler error) - which is correct operation, IMHO.
>
>
>
> Well, Java doesn't do pass by reference, but it allows pass-by-value of
> references to temporary objects, e.g.:
>
> class Donkey
> {
> public Donkey(String name)
> {
> this.name = name;
> }
>
> public String name;
> }
>
>
> public class test
> {
> static Donkey foo()
> {
> return new Donkey("Eeyore");
> }
>
> static void bar(Donkey d)
> {
> System.out.println("Donkey name: " + d.name);
> }
>
> public static void main(String[] args)
> {
> // pass value of reference to temp object
> bar(foo());
> }
> }
>
> C++ gets round this if the function is expecting a const reference, e.g.:
>
> int foo()
> {
> return 4;
> }
>
> void bar (const int &i) // expecting const reference
> {
> printf("Value: %d\n", i);
> }
>
> int main()
> {
> bar(foo()); // pass temp value
>
> return 0;
> }
>
> Obviously, PHP doesn't really do type-checking, so a PHP equivalent of
> const could never be enforced.
>
> Which is a shame, as it means that one can't differentiate between
> passing by reference to eliminate object copying, and passing by
> reference to allow alteration of the original object.
>
> However, even in Jerry's example, even without the benefit of const
> enforcement, I don't see why PHP can't just assign to the temporary
> variable - what harm would it do?
>
>

Yes, C++ allows a *const* reference. But it doesn't allow a non-const
reference.

But then let's take another case:

f1(3);

NOW what does f1 increment?


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация