Title: Consider defensive coding when retrieving order objects
Last modified: August 12, 2024

---

# Consider defensive coding when retrieving order objects

 *  [Barry](https://wordpress.org/support/users/barryhughes-1/)
 * (@barryhughes-1)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/consider-defensive-coding-when-retrieving-order-objects/)
 * Hi! 👋
 * We were trying to track down a reported error with a stacktrace as follows:
 *     ```wp-block-code
       #0 /.../wp-content/plugins/woocommerce/includes/class-wc-data-store.php(159):  Abstract_WC_Order_Data_Store_CPT->read(Object(WC_Order))#1 /.../wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-order.php(114):   WC_Data_Store->read(Object(WC_Order))#2 /.../wp-content/plugins/woo-razorpay/includes/razorpay-webhook.php(158):   WC_Abstract_Order->__construct('3001004173')#3 /.../wp-content/plugins/woo-razorpay/includes/razorpay-webhook.php(103):    RZP_Webhook->paymentAuthorized(Array)#4 /.../wp-content/plugins/woo-razorpay/woo-razorpay.php(986):    RZP_Webhook->process()#5 /.../wp-includes/class-wp-hook.php(324):    razorpay_webhook_init('')
       ```
   
 * We think this may come from a much older version of the RazorPay plugin, as we
   don’t see any direct instantiations of order objects in the current webhook class.
   However, I wanted to reach out as we spotted a [somewhat similar problem](https://plugins.trac.wordpress.org/browser/woo-razorpay/tags/4.6.7/includes/razorpay-webhook.php#L157)
   in your current code:
 *     ```wp-block-code
       $order = wc_get_order($orderId);$rzpWebhookNotifiedAt = $order->get_meta('rzp_webhook_notified_at');
       ```
   
 * This is probably fine, 99% of the time, but `wc_get_order()` can also return `(
   bool) false`, so there is a risk you may attempt to call a method on a boolean,
   which would lead to a fatal error (this could occur as the result of a race condition,
   in which the order is deleted by a concurrently running process).

The topic ‘Consider defensive coding when retrieving order objects’ is closed to
new replies.

 * ![](https://ps.w.org/woo-razorpay/assets/icon-256x256.png?rev=2257034)
 * [Razorpay for WooCommerce](https://wordpress.org/plugins/woo-razorpay/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woo-razorpay/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woo-razorpay/)
 * [Active Topics](https://wordpress.org/support/plugin/woo-razorpay/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woo-razorpay/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woo-razorpay/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [Barry](https://wordpress.org/support/users/barryhughes-1/)
 * Last activity: [1 year, 9 months ago](https://wordpress.org/support/topic/consider-defensive-coding-when-retrieving-order-objects/)
 * Status: not a support question