我试图将json解码对象传递给类的方法。但是当我尝试访问该对象的属性时,它会发出通知:尝试获取非对象php的属性。但是当我将该对象变量写入文件时,它会显示所有数据。
我试图在memberpress插件发送webhook事件时使用api更新hubspot数据。
以下是我正在做的事情:
文件:hubspotsync.php
require_once 'class-synchronize.php';
class HubspotSync{
public function init()
{
$encoded_data = file_get_contents('php://input');
if( $encoded_data != '' ){
$data = json_decode($encoded_data);
$this->perform_action($data);
}
}
private function perform_action($data)
{
$synchronize = new Synchronize();
$synchronize->perform_sync($data);
unset($synchronize);
}
}
$sync = new HubspotSync();
$sync->init();
unset($sync);
文件:class-syncronize.php
class Synchronize{
public function perform_sync($eventobj)
{
// If I fwrite this $eventObj to a file, it looks like as below. but gives an notice on next code. why???
$event_type = $eventobj->event; // This line gives the notice.
}
}
$ eventobj如下所示:
stdClass Object
(
[event] => subscription-created
[type] => subscription
[data] => stdClass Object
(
[coupon] =>
[membership] => stdClass Object
(
[id] => 16
[title] => Monthly Subscription
[content] =>
[excerpt] =>
[date] => 2016-09-16 19:22:07
[status] => publish
[author] => 4
[date_gmt] => 2016-09-16 19:22:07
[modified] => 2017-09-27 15:19:04
[modified_gmt] => 2017-09-27 20:19:04
[group] => 0
[price] => 28.00
[period] => 1
[period_type] => months
[signup_button_text] => Sign Up
[limit_cycles] =>
[limit_cycles_num] => 2
[limit_cycles_action] => expire
[trial] =>
[trial_days] => 0
[trial_amount] => 0.00
[trial_once] => 1
[group_order] => 0
[is_highlighted] =>
[pricing_title] => Monthly Subscription
[pricing_show_price] => 1
[pricing_display] => auto
[custom_price] =>
[pricing_heading_txt] =>
[pricing_footer_txt] =>
[pricing_button_txt] => Sign Up
[pricing_button_position] => footer
[pricing_benefits] => Array
(
[0] =>
)
[register_price_action] => default
[register_price] =>
[thank_you_page_enabled] => 1
[thank_you_message] => Thank you for signing up for a monthly subscription to The Prudent Speculator. Please contact info@theprudentspeculator.com with any questions regarding your subscription. Your login credentials should be e-mailed to you shortly.
[custom_login_urls_enabled] =>
[custom_login_urls_default] =>
[custom_login_urls] => Array
(
)
[expire_type] => delay
[expire_after] => 1
[expire_unit] => days
[expire_fixed] => 2017-09-27
[tax_exempt] =>
[allow_renewal] =>
[access_url] =>
[disable_address_fields] =>
[simultaneous_subscriptions] =>
[use_custom_template] =>
[custom_template] => custom/page-archive.php
[customize_payment_methods] => 1
[custom_payment_methods] => Array
(
[0] => owyg62-7fu
)
[customize_profile_fields] => 1
[custom_profile_fields] => Array
(
[0] => mepr_phone
[1] => mepr_username
)
[cannot_purchase_message] => You don't have access to purchase this item.
)
[member] => stdClass Object
(
[id] => 25
[email] => craig.andrews@allies4me.com
[username] => craigandrews
[nicename] => craigandrews
[url] =>
[message] =>
[registered_at] => 2017-10-16 20:56:16
[ip] => 24.27.9.104
[first_name] => Craig
[last_name] => Andrews
[display_name] => craigandrews
)
[id] => 7
[subscr_id] => mp-sub-59e7cdb3d47e0
[response] =>
[gateway] => stdClass Object
(
[name] => PayPal Payments Pro
[label] => Paypal
[use_label] => 1
[icon] => https://prudent2.wpengine.com/wp-content/plugins/memberpress/images/checkout/cards.png
[use_icon] => 1
[desc] => Pay with your credit card via PayPal
[use_desc] => 1
[id] => owyg62-7fu
[settings] => stdClass Object
(
[gateway] => MeprPayPalProGateway
[id] => owyg62-7fu
[label] => Paypal
[use_label] => 1
[icon] => https://prudent2.wpengine.com/wp-content/plugins/memberpress/images/checkout/cards.png
[use_icon] => 1
[desc] => Pay with your credit card via PayPal
[use_desc] => 1
[api_username] => kbroughton_api1.afamcapital.com
[api_password] => 48UDEBHJBB6RXNVY
[signature] => AQUF7rVduRDHYM-3AIBZaDFk-4ZYAZQgmcG7B9LdUmyA7fRkA9Mk1gPj
[sandbox] => on
[force_ssl] => on
[debug] =>
[saved] => 1
[url] => https://www.sandbox.paypal.com/cgi-bin/webscr
[api_url] => https://api-3t.sandbox.paypal.com/nvp
[api_version] => 69
)
[capabilities] => Array
(
[0] => process-payments
[1] => process-refunds
[2] => create-subscriptions
[3] => cancel-subscriptions
[4] => update-subscriptions
[5] => suspend-subscriptions
[6] => resume-subscriptions
[7] => subscription-trial-payment
)
)
[ip_addr] => 70.112.70.86
[price] => 28.00
[period] => 1
[period_type] => months
[limit_cycles] => 0
[limit_cycles_num] => 2
[limit_cycles_action] => expire
[prorated_trial] => 0
[trial] => 0
[trial_days] => 0
[trial_amount] => 0.00
[status] => pending
[created_at] => 2017-10-18 21:54:59
[total] => 28.00
[tax_rate] => 0.000
[tax_amount] => 0.00
[tax_desc] =>
[tax_class] => standard
[cc_last4] =>
[cc_exp_month] =>
[cc_exp_year] =>
[token] =>
[tax_compound] => 0
[tax_shipping] => 1
)
)
答案 0 :(得分:0)
var_dump( $eventObj )
并确保该对象上实际存在event
属性。它可能是$eventObj['event']
或类似的奇怪之处。该错误告诉您event
$eventObj