Jump to content

OOP help


bugcoder

Recommended Posts

i have a class

 

class UploadHandler
{
    public $options;
    
    function __construct($options=null) {
        $this->options = array(
            'upload_dir' => ROOT.DS.'files'.DS.'Jupload/',
            'param_name' => 'files',
            'max_file_size' => null,
            'min_file_size' => 1
        );
        if ($options) {
            $this->options = array_replace_recursive($this->options, $options);
        }
    }

.................other code 

}

 

How can i change the options $this->options['upload_dir'] by calling this class in other class?

Please help with example.

Link to comment
https://forums.phpfreaks.com/topic/254278-oop-help/
Share on other sites

        if ($options) {
            $this->options = array_replace_recursive($this->options, $options);
        }

 

This condition checks if you passed any $options to the constructor method, and if so replaces them in $this->options. So although you do originally define the 'upload_dir' key, the call to array_replace_recursive() overwrites it.

Link to comment
https://forums.phpfreaks.com/topic/254278-oop-help/#findComment-1303767
Share on other sites

That's not what I posted before. The parameter in the constructor accepts an array of options, not an array with an 'options' key containing an array of options.

 

Structure of yours:

array(
    "options" => array(
        "upload_dir" => ROOT.DS.'files'.DS.'newDire'
    )
)

 

Mine:

array(
    "upload_dir" => ROOT.DS.'files'.DS.'newDire'
)

 

 

Link to comment
https://forums.phpfreaks.com/topic/254278-oop-help/#findComment-1303772
Share on other sites

Thank you a lot for your great help indeed in both OOP and 5.3 version issue.......................

 

yes it was not working also coz of 5.3 version

 

now from php site i have found function that does same work as array_replace_recursive from this link and my code worked...

link is http://php.net/manual/en/function.array-replace-recursive.php and its user contributed code by "Gregor at der-meyer dot de"

 

Thanks again Adam!!!

Link to comment
https://forums.phpfreaks.com/topic/254278-oop-help/#findComment-1303780
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.