I'm trying to send my $_POST data to a class of mine for processing... but it doesn't seem to matter how I send it, PHP is telling me:
Trying to get property of non-object
Class method:
public function test_me_out($postdata) {
if(isset($postdata->price)) {
return "the price was: " . $postdata->price . " …and this was added.开发者_如何转开发";
} else {
return "it's apparently not set...";
}
}
$_POST
is not an object. You should access its information using it as an array like $_POST['my_data']
.
You can still do
$postData = new ArrayObject($_POST,ArrayObject::ARRAY_AS_PROPS);
Then $postData->price
will work as expected to be.
How are you calling test_me_out? Like this?
test_me_out($_POST)
$_POST is an array, not an object. Therefore you can access the variables in your function like so:
$postdata['price']
精彩评论