Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP constructor executes before arguments for nested variables can be supplied
    primarykey
    data
    text
    <p>First things first, here is a little snippet code to help explain my problem:</p> <pre><code>&lt;?php class foo { public $title; __construct{ echo "&lt;html&gt;\n"; echo "&lt;head&gt;\n"; echo "&lt;title&gt;".$this-&gt;title."&lt;/title&gt;\n"; echo "&lt;/head&gt;\n"; echo "&lt;body&gt;\n"; } /** * * I get $title from index.php * */ public function setTitle( $title ) { $this-&gt;title = $title; } __destruct{ echo "&lt;/body&gt;\n"; echo "&lt;/html&gt;\n"; } } ?&gt; </code></pre> <p>You've probably noticed already that this code will produce a title of well, . Yah, there's an empty space there. <b>:- )</b></p> <p>To me this actually makes perfect sense (even if I wasn't expecting it) because the class constructor is being executed on the creation of the foo object meaning that it doesn't wait around for index.php to supply the argument for <code>setTitle()</code> which in turn returns the string that fills <code>$this-&gt;title</code>.</p> <p>So if I truly understand whats going on here, what can I do to get around this issue? Should I be buffering the output using the built in buffer functions, and then modifying the stored output with the supplied title string? Any ideas?</p> <p>I would really, really, really, like to keep this structure where the constructor and destructor contain this repetitive code. Its nice that these functions don't have to be called anywhere. I understand that some developers may consider this bad practice, but I am going to do it this way anyway because I want to because I think its cool. So i'm not really looking for advice in that aspect, unless you feel extremely motivated to inform me on my stupidity.</p> <p>So, if you have any advice/ideas/knowlege to share with me that would be great.</p> <p>Thanks, and feel free to take your time because I guess i'm going to be forced to stay inside hiding from the evil swine flu that has come to my city, so no rush!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload