You are here: Re: Passing an array as a reference to a function « PHP Programming Language « IT news, forums, messages
Re: Passing an array as a reference to a function

Posted by countach on 10/10/06 13:55

En las nuevas, el Bit Byte escribiσ:
> Noobie here (C++/C/Java experience though) ...
>
> Recently picked up PHP ...
>
> I want to pass an array to a function and then to use count on the
> passed variable - is this the way to do it (its an object method) :
>
> public function foo(array& $arr)
> {
> if (count($arr) < 1)
> throw new MyException("Blah blah ...") ;
> ....
> }
>
>
> I have two questions for the pros:
>
> 1). Is the function signature correct (valid syntax?)
> 2). Can count accept a reference type variable ?

1) Correct syntax:

public function foo(&$arr)
{
if (count($arr) < 1)
throw new MyException("Blah blah ...") ;
....
}

2) Yes

 

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

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация