duanjia4097 2014-11-17 13:04
浏览 11
已采纳

在调用PHP方法之前设置$ _POST数据

Is it possible to set $_POST data before calling another PHP method?

I'm trying to call a method from another PHP class. That method do not accept any arguments, it only takes $_POST data. So, my question is: is it possible to do something like this?

$_POST['name'] = 'John';

$user = new User();
$user->create();

The method "create" from the class "User" gets the $_POST['name'] data to create the record. Does it work?

  • 写回答

1条回答 默认 最新

  • dso15221 2014-11-17 13:35
    关注

    Yes, you can do like this.

    Since $_POST is a superglobal associative array, you can change the values like a normal php array. Take a look at this piece of code. It will print "Hai".

    <?php
     class first{
       public function index(){
         $_POST['text'] = 'Hai';
         $scnd = new second();
         $scnd->disp();
       }
     }
     class second{
       public function disp(){
         $cc = $_POST['text'];
         echo $cc;
       }
     }
     $in = new first();
     $in->index();
     ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 经gamit解算的cors站数据再经globk网平差得到的坐标做形变分析
  • ¥15 GD32 SPI通信时我从机原样返回收到的数据怎么弄?
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!