dpgjci27392 2009-11-28 22: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 11: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条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c