Re: segmentation fault - my fault?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jochem Maas wrote:
Marc Weber wrote:
Does this script cause a segmentation fault running on your php
interpreter, too?

=============  =======================================================
<?php

function fa()
{
  $res = array();
  foreach(func_get_args() as $a)

you can't use the return value of func_get_args() directly in this way.
you must do this instead:

$args = func_get_args();
foreach ($args as $a)

Since when? The syntax he used has always worked for me.
    if (is_array($a)){
      foreach(fa($a) as $a2)
        $res[]=$a2;
    }else
      $res[]=$a;
  return $res;
}

var_dump(fa(array(1,2),array(array(3,4),array(5,6))));
?>
=============  =======================================================

My version:
marc@localhost ~ $ php -v
PHP 5.1.6-pl6-gentoo (cli) (built: Feb 11 2007 02:37:11)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies

This function should take all elements in all arrays and flatten them down to one array.
Thus the result of the example above should be
array(1,2,..,6)

Marc




--
Jeremy C. Privett
Chief Operating Officer
Zend Certified Engineer
Completely Unique
jprivett@xxxxxxxxxxxxxxxxxxxx

Phone:     303.459.4819
Mobile:    303.883.0312
Fax:       303.459.4821
Web:       www.completelyunique.com

This email may contain confidential and privileged material for the sole use of the intended recipient. Any review or distribution by others is strictly prohibited. If you are not the intended recipient please contact the sender and delete all copies. Your compliance is appreciated.


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux