dpgjci27392 2009-11-28 14:29
浏览 39
已采纳

如何将数组加变量传递给PHP中的函数?

I have a function prototype as such:

function do_upload( $file, $id, $type )

And I'm calling the function like this:

$this->do_upload( $files, $id, 'article' );

However, only $files is actually being passed through to the function. I'm sure it's simple but what have I done wrong?

EDIT:

So $file is just an array of file information, similar to $_FILES and it is passed through fine, I do some manipulation of it further in the function.

$id is set before I call the function, if I print_r() before the function call I see an ID I would expect and $type is just a string.

However, If I print_r() or die() on either $id or $type they are both blank and var_dump() returns the following:

die( var_dump( $id ) ); -> string(0) ""
die( var_dump( $type ); -> bool(false)

Right before the function call: die( var_dump( $id) ); -> string(3) "111"

Any ideas?

SOLUTION:

In case anyone has a similar problem, check the accepted answer below. Essentially I needed to pass the $files array by reference as it was using up the available stack space.

Thanks

  • 写回答

5条回答 默认 最新

  • dongpengqin3898 2009-11-29 03:31
    关注

    I think your actually running out of stack space (or whatever space php uses internally for call stacks) for the function call. Try passing $files by reference. Equally try passing just a string to $files and see if that brings the other parameters back.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部