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?
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();
?>