0

I am not sure if my function is firing before another funciton or if I am having issues with the $this variable when I am extending my class.

I am creating a function in my functions.php file. Here's a link to my function.

The specific function is extending a class that is an extension for WooCommerce. The template page calls the function like so:

<?php
    $ssi_woocommerce_variation_control_output = new SSi_WC_Swatch_Picker( $product->id, $attributes, $variation_params['selected_attributes'] );
    print_r($ssi_woocommerce_variation_control_output);
    $ssi_woocommerce_variation_control_output->picker();
?>

The print_r output will produce the array content to the page. However I get this:

Start the Loop

Notice: Undefined property: SSi_WC_Swatch_Picker::$attributes in /my_url/wp-content/themes/my-theme/functions.php on line 13

Warning: Invalid argument supplied for foreach() in /my_url/wp-content/themes/my-theme/functions.php on line 13

End the Loop

UPDATE Good news (at least for me) the developer of the original class is going to change the private properties to protected and then I can access them without issue.

2
  • I changed the title to reflect better what was happening.
    – Ken
    Commented Dec 30, 2014 at 5:31
  • I have also decided based off the properties being private to just extend the class and re-use the entire class and adjust the picker() method to suite my needs.
    – Ken
    Commented Dec 30, 2014 at 5:33

1 Answer 1

3

Probably $attribute is declared as private in the super class, so you can't access it directly from subclasses.

5
  • Yup I looked at the class I'm extending, it has that set to private. So is there nothing I can do then? Would proving the superclass code be beneficial at this point?
    – Ken
    Commented Dec 29, 2014 at 17:15
  • 1
    If parent class provides getter methods for these variables you have to use them.
    – jep
    Commented Dec 29, 2014 at 17:47
  • This is quickly spiraling out of my wheelhouse. How would I find out if there are getter methods? I created a paste of the original class here. pastebin.com/EWCn7UCX
    – Ken
    Commented Dec 29, 2014 at 18:22
  • 1
    Getter methods are methods that returns an object property. If your parent class has these properties set as private and doesn't provide getter method, maybe the author doesn't want let other to manipulate them and you have to find a workaround to deal with them. You can always modify visibility of that attributes to protected ( not private ) but this is dangerous because others can use that class.
    – jep
    Commented Dec 29, 2014 at 20:01
  • As a little experiment I changed the attributes private to protected and they appeared on the page correctly. Now I need to figure out how to achieve this without editing the core plug-in or if it is even possible.
    – Ken
    Commented Dec 29, 2014 at 23:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.