vivekrajenderan / simplesamlphp

Automatically exported from code.google.com/p/simplesamlphp
Other
0 stars 0 forks source link

Use require and not require_once in SimpleSAML_XHTML_Template show() method #385

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm not sure if there is some reason (side effect) using require instead of 
require once in the simplesaml template show method, but i found that if you 
wanna use a template more than once in a single php script (think at the Mailer 
and the mail template, for instance i modified the selfregister module to send 
single mails to a list of LDAP administrators with single tokenized links to 
approve an user, so i needed to instantiate the mail template more than once in 
a single script and i got blank emails after the first one)

so i modified the code in this way:

    /**
         *
     * Show the template to the user.
         *
         * @param boolean $useRequireOnce set it to false when you want to reuse the template more times in a script (e.g. a mass mailer)
         */
    public function show($useRequireOnce=true) {

        $filename = $this->findTemplatePath($this->template);
                if ($useRequireOnce){
        require_once($filename);
                }else{
                    require($filename);
                }
    }

this because i wanted to avoid possible side effects,
but i think that all will works correclty also using always require, because 
require_once is useful to avoid double function delcarations and similar 
things, but in the simplesamlphp templates i think there aren't similar things, 
but just formatting and view code.

Original issue reported on code.google.com by rastrano on 24 Jan 2011 at 9:09

GoogleCodeExporter commented 9 years ago
I agree that we should just use require() here. I cannot think of any reason 
why we would want require_once().

Original comment by olavmrk@gmail.com on 24 Jan 2011 at 12:01

GoogleCodeExporter commented 9 years ago
Done in r3188.

Original comment by jaim...@gmail.com on 12 Oct 2012 at 11:27