mercredi 7 avril 2021

How to avoid a bug that crashes the PHP script instance when attempting to use ReflectionProperty::getValue?

I have to do the following reflection code because the WooCommerce version I have available has a bug (v4.9.0).

Please see the comments in the code below:

// checked before the existence of the class with class_exists
$rp = new ReflectionProperty('WC_Product_Variable_Data_Store_CPT', 'prices_array');
$rp->setAccessible(true);
var_dump('start'); // echoes something to the html code
$protected_prices_array = $rp->getValue($ths); // crashes the PHP script instance
var_dump('stop'); // this is not printed anymore

If requested, I can offer more code.

Currently I am attempting to inherit the given class to see if I can walk around the bug.

On staging site I have PHP 7.4.16.

Update 1

I have this code in my own function my_read_price_data( $ths, &$product, $for_display = false ) { ... which does the same as WC's data store's read_price_data public method which accesses the prices_array property which is protected.





Aucun commentaire:

Enregistrer un commentaire