Re: [PHP] Function-return-array idea

2008-01-17 Thread Nathan Nobbe
On Jan 16, 2008 6:32 PM, Stijn Leenknegt [EMAIL PROTECTED] wrote:

 Hello

 I've an idea for PHP6. Let's kickoff with an example.

 ?php
 $info = getUserInformation($id); //return an array with all the
 information
 of an user.
 echo $info['naam'];
 ?

 This is nice, but when I want one element of the returned array, I have to
 store the returned array into a variable and then call the variable.
 The next code example is my idea.

 ?php
 echo getUserInformation($id)['naam'];
 ?

 Let's look further then this small example.

 ?php
 echo $object-fetchObjects()[0]-method();
 ?

 This example is more realistic when you use OO. This code style is faster
 for developing applications. This code style is available in Java,
 Javascript, C, C++, Perl, Python, ... So why not in PHP(6)? You can read
 more on my blog


i think this is pretty much a dup of a thread from about a week ago;
http://www.nabble.com/Why-is-some_function()-some_index--invalid-syntax--td14749459.html

-nathan


Re: [PHP] Function-return-array idea

2008-01-17 Thread Eric Butera
On Jan 16, 2008 6:32 PM, Stijn Leenknegt [EMAIL PROTECTED] wrote:
 Hello

 I've an idea for PHP6. Let's kickoff with an example.

 ?php
 $info = getUserInformation($id); //return an array with all the information
 of an user.
 echo $info['naam'];
 ?

 This is nice, but when I want one element of the returned array, I have to
 store the returned array into a variable and then call the variable.
 The next code example is my idea.

 ?php
 echo getUserInformation($id)['naam'];
 ?

 Let's look further then this small example.

 ?php
 echo $object-fetchObjects()[0]-method();
 ?

 This example is more realistic when you use OO. This code style is faster
 for developing applications. This code style is available in Java,
 Javascript, C, C++, Perl, Python, ... So why not in PHP(6)? You can read
 more on my blog.

 http://www.eos-team.org/2007/09/06/php6-function-return-array-idea.html

 I hope for good response and also response from php-dev team.

 Greetings
 Stijn Leenknegt


My reply is a bit pointless as I'd never do/rely on this.  But
nonetheless it was an interesting test.

function testObj() {
$arr = array();
$arr['key1'] = array(1, 2, 3);
$arr['key3'] = array('a','b','c');
return (object)$arr;
}

echo 'pre';

echo Key1: \n;
print_r(testObj()-key1);
echo Key3: \n;
print_r(testObj()-key3);


--- output 
Key1:
Array
(
[0] = 1
[1] = 2
[2] = 3
)
Key3:
Array
(
[0] = a
[1] = b
[2] = c
)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Function-return-array idea

2008-01-17 Thread Jim Lucas

Jim Lucas wrote:
I think this would be an easier/quicker fix for you then requesting that 
the PHP developers re-write a large portion of the way PHP currently works.




Here is the reference that I have been looking for.

http://en.wikipedia.org/wiki/Message_passing

Jim

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Function-return-array idea

2008-01-16 Thread Stijn Leenknegt
Hello

I've an idea for PHP6. Let's kickoff with an example.

?php
$info = getUserInformation($id); //return an array with all the information
of an user.
echo $info['naam'];
?

This is nice, but when I want one element of the returned array, I have to
store the returned array into a variable and then call the variable.
The next code example is my idea.

?php
echo getUserInformation($id)['naam'];
?

Let's look further then this small example.

?php
echo $object-fetchObjects()[0]-method();
?

This example is more realistic when you use OO. This code style is faster
for developing applications. This code style is available in Java,
Javascript, C, C++, Perl, Python, ... So why not in PHP(6)? You can read
more on my blog.

http://www.eos-team.org/2007/09/06/php6-function-return-array-idea.html

I hope for good response and also response from php-dev team.

Greetings
Stijn Leenknegt


Re: [PHP] Function-return-array idea

2008-01-16 Thread Richard Lynch
On Wed, January 16, 2008 5:32 pm, Stijn Leenknegt wrote:
 I've an idea for PHP6. Let's kickoff with an example.

This belongs on php-internals...

 ?php
 echo getUserInformation($id)['naam'];
 ?

where it has already been discussed at length, and, as I recall,
rejected as too obfuscated for the intent of PHP.

I apologize to php-internals for my gross over-simplification of a
zillion posts. :-)

Read the php-internals archives for the gory details.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Function-return-array idea

2008-01-16 Thread Jim Lucas
I think this would be an easier/quicker fix for you then requesting that 
the PHP developers re-write a large portion of the way PHP currently works.



?php

function i($arr, $i) {
return $arr[$i];
}

echo i(getUserInformation($id), 'naam');
#or
echo i($object-fetchObjects(), 0)-method();

?

Stijn Leenknegt wrote:

Hello

I've an idea for PHP6. Let's kickoff with an example.

?php
$info = getUserInformation($id); //return an array with all the information
of an user.
echo $info['naam'];
?

This is nice, but when I want one element of the returned array, I have to
store the returned array into a variable and then call the variable.
The next code example is my idea.

?php
echo getUserInformation($id)['naam'];
?

Let's look further then this small example.

?php
echo $object-fetchObjects()[0]-method();
?

This example is more realistic when you use OO. This code style is faster
for developing applications. This code style is available in Java,
Javascript, C, C++, Perl, Python, ... So why not in PHP(6)? You can read
more on my blog.

http://www.eos-team.org/2007/09/06/php6-function-return-array-idea.html

I hope for good response and also response from php-dev team.

Greetings
Stijn Leenknegt




--
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Function-return-array idea

2008-01-16 Thread Per Jessen
Stijn Leenknegt wrote:

 This is nice, but when I want one element of the returned array, I
 have to store the returned array into a variable and then call the
 variable. The next code example is my idea.
 
 ?php
 echo getUserInformation($id)['naam'];
 ?
 
 Let's look further then this small example.
 
 ?php
 echo $object-fetchObjects()[0]-method();
 ?

Yeah, I like the idea.  I've often used that style out of habit, only to
have to revert to assigning the result to a variable etc. 
I don't know why it isn't supported by PHP, but I suspect it is related
to the type-concept. 


/Per Jessen, Zürich

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Function-returning array { OR } declare array at top of functions file?

2006-03-21 Thread Michael Hulse

Hi,

I just wanted to know if it is wrong, or non-standard, for me to set-up  
functions that just return an array... example:


 function vert_links_array():
function vert_links_array() {
return array(
		'1' =  
array(S_MANCOM,'start.php?page=productsamp; 
sub=mancom',S_MANCOM_TI,'mancom'),
		'2' =  
array(S_BRACLU,'start.php?page=productsamp; 
sub=braclu',S_BRACLU_TI,'braclu'),
		'3' =  
array(S_BRASHO,'start.php?page=productsamp; 
sub=brasho',S_BRASHO_TI,'brasho'),
		'4' =  
array(S_CALDIS,'start.php?page=productsamp; 
sub=caldis',S_CALDIS_TI,'caldis'),
		'5' =  
array(S_CUSMAN,'start.php?page=productsamp; 
sub=cusman',S_CUSMAN_TI,'cusman'),
		'6' =  
array(S_FRIDIS,'start.php?page=productsamp; 
sub=fridis',S_FRIDIS_TI,'fridis'),
		'7' =  
array(S_GOVMIL,'start.php?page=productsamp; 
sub=govmil',S_GOVMIL_TI,'govmil'),
		'8' =  
array(S_INDBRA,'start.php?page=productsamp; 
sub=indbra',S_INDBRA_TI,'indbra'),
		'9' =  
array(S_INDLIN,'start.php?page=productsamp; 
sub=indlin',S_INDLIN_TI,'indlin'),
		'10' =  
array(S_RAICAR,'start.php?page=productsamp; 
sub=raicar',S_RAICAR_TI,'raicar'),
		'11' =  
array(S_SAWGUI,'start.php?page=productsamp; 
sub=sawgui',S_SAWGUI_TI,'sawgui'),
		'12' =  
array(S_ASSPRO,'start.php?page=productsamp; 
sub=asspro',S_ASSPRO_TI,'asspro')

); // Add more here.
}

OR

Should I just put the above array at the top of my functions file and  
access it as a global within other functions?


Any suggestions? I am a self-taught php dude, so please don't laugh if  
this is a silly question.


Thanks.  :)
Cheers,
Micky

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Function-returning array { OR } declare array at top of functions file?

2006-03-21 Thread Michael Hulse


On Mar 21, 2006, at 2:35 PM, Michael Hulse wrote:
Any suggestions? I am a self-taught php dude, so please don't laugh if 
this is a silly question.


You know, the more I think about, the more I think I need to learn 
about PHP classes... Seems like I would just be able to define the 
array from previous email within the a class that have all the 
functions that use that array... not sure if that makes sense... any 
good links for learning more about classes?


Thanks,
Micky

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Function-returning array { OR } declare array at top of functions file?

2006-03-21 Thread Michael Hulse

On Mar 21, 2006, at 3:48 PM, Michael Hulse wrote:

... any good links for learning more about classes?


This seems like a good tutorial to start with:

http://www.phpfreaks.com/tutorials/48/0.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] function returning array

2003-09-07 Thread Leonie
How do I get a function to return an array?  This code doesn't work:

 function getData() {
  function builds the array  $theArray - tested ok
 return $theArray;
}

Any help on the syntax would be appreciated.

Cheers
Leonie

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] function returning array

2003-09-07 Thread Tom Rogers
Hi,

Monday, September 8, 2003, 11:54:10 AM, you wrote:
L How do I get a function to return an array?  This code doesn't work:

L  function getData() {
L   function builds the array  $theArray - tested ok
L  return $theArray;
L }

L Any help on the syntax would be appreciated.

L Cheers
L Leonie

That should work

what do you get with this:

$array = getData();
print_r($array);

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] function returning array

2003-09-07 Thread Leonie
Nothing.  But it I run:

function getData() {
etc..
print_r ($theArray);
return $theArray;
}
the data is definitely there.

I should add that the function is within a class so it is like this:

class excel_com  {
(all tested - it works well)
function getData() {
etc..
return $theArray;
}
}

and here is an example of the call:

  $xls = new excel_com($workbook, $wks);
  $xls-Range($range, $inclHeader);
  $header=$xls-header;
  $data = $xls-getData();
  $xls-close();
  unset($xls);


 what do you get with this:

 $array = getData();
 print_r($array);

 -- 
 regards,
 Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] function returning array

2003-09-07 Thread Tom Rogers
Hi,

Monday, September 8, 2003, 12:16:47 PM, you wrote:
L Nothing.  But it I run:

L function getData() {
L etc..
L print_r ($theArray);
L return $theArray;
L }
L the data is definitely there.

L I should add that the function is within a class so it is like this:

L class excel_com  {
L (all tested - it works well)
L function getData() {
L etc..
L return $theArray;
L }
L }

L and here is an example of the call:

L   $xls = new excel_com($workbook, $wks);
L   $xls-Range($range, $inclHeader);
L   $header=$xls-header;
L   $data = $xls-getData();
L   $xls-close();
L   unset($xls);

Well from what is there that should work...very strange
does print_r show an empty array or nothing?

is $theArray created in the getData() function or is part of the class and
needs return $this-theArray


-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] function returning array

2003-09-07 Thread Larry E . Ullman
Nothing.  But it I run:

function getData() {
etc..
print_r ($theArray);
return $theArray;
}
the data is definitely there.
I think the example in the PHP manual goes something like...

function getData () {
// blah, blah
return array ('value1', 'value2', ...);
}
Then you would call it with
list ($var1, $var2, ...) = getData();
Hope that helps,
Larry
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] function for $array

2003-03-21 Thread Marek Kilimajer
I would use foreach instead of for, your function does not guarantie 
checking all elements and also checks elements that might not have been set.

pei_world wrote:

I want to use the following function the test the array elements,
if all element is number return true, otherwise false;
but the command marked, it print out only the first char of every strings in
the array;
can help?
ie: ++0++ for 0.234

function check_int_float($array){
 $result=true;
  for($i=0; $isizeof($array); $i++){
echo ++.$array[$i].++;==
   if($array[$i]!=){
 if(is_numeric($array[$i])){
 $result=true;
}else{
 $result=false;
  break;
 }//if
   }//if
   }//foreach
return $result;
}
--
Sincerely your;
pei_world ( .::IT::. )





 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] function for $array

2003-03-20 Thread pei_world
I want to use the following function the test the array elements,
if all element is number return true, otherwise false;
but the command marked, it print out only the first char of every strings in
the array;
can help?

ie: ++0++ for 0.234

 function check_int_float($array){
  $result=true;

   for($i=0; $isizeof($array); $i++){
 echo ++.$array[$i].++;==
if($array[$i]!=){
  if(is_numeric($array[$i])){
  $result=true;
 }else{
  $result=false;
   break;
  }//if
}//if
}//foreach
 return $result;
 }

--
Sincerely your;

pei_world ( .::IT::. )






-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Fw: [PHP] function for $array

2003-03-20 Thread Kevin Stone

- Original Message -
From: pei_world [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, March 20, 2003 4:30 PM
Subject: [PHP] function for $array


 I want to use the following function the test the array elements,
 if all element is number return true, otherwise false;
 but the command marked, it print out only the first char of every strings
in
 the array;
 can help?

 ie: ++0++ for 0.234

  function check_int_float($array){
   $result=true;

for($i=0; $isizeof($array); $i++){
  echo ++.$array[$i].++;==
 if($array[$i]!=){
   if(is_numeric($array[$i])){
   $result=true;
  }else{
   $result=false;
break;
   }//if
 }//if
 }//foreach
  return $result;
  }

 --
 Sincerely your;

 pei_world ( .::IT::. )


There are some (what I would call) engineering issues with your  function
but it looks like it should work.  Maybe your problem lies in the array?

// Cleaned up function..
function array_is_numeric($array)
{
 $result=true;
 for($i=0; $isizeof($array); $i++)
 {
   if(!is_numeric($array[$i]))
   $result=false;
 }
 return $result;
}

- Kevin



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php