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
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
Share on other sites

but im getting error when iniating class like this

 

$upload_handler = new UploadHandler( array("options" => array("upload_dir"=>ROOT.DS.'files'.DS.'newDire') ));

 

the error is

 

Fatal error: Call to undefined function array_replace_recursive() in D:\xampp\htdocs\...

 

Link to comment
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.