Re: Why does PHP have such a pain in the a$$ configurationfile?
| From: | Shawn McKenzie | Date: | Tue, 26 May 2009 17:57:35 +0000 |
| Subject: | Re: Why does PHP have such a pain in the a$$ configurationfile? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-293165@lists.php.net to get a copy of this message | ||
Robert Cummings wrote:
> On Tue, 2009-05-26 at 18:30 +0100, hessiess@hessiess.com wrote:
>> Something that seriously annoys me about PHP is the fact that it has
>> a configuration file which can *completely* change the behaviour of
>> the language. Take the following for example:
>> ----------------------------------------------
>> function parse_to_variable($tplname, $array = array())
>> {
>> $fh = fopen($tplname, 'r');
>> $str = fread($fh, filesize($tplname));
>> fclose($fh);
>>
>> extract($array);
>>
>> ob_start();
>> eval($str);
>> $result = ob_get_contents();
>> ob_end_clean();
>> return $result;
>> }
>> ----------------------------------------------
>>
>> Which would take a template file like this (DTD etc left out):
>> ----------------------------------------------
>> <p>List:</p>
>> <ul>
>> <?php foreach($array as $item): ?>
>>
>> <li><php echo($item); ?></li>
>> <?php endforeach; ?>
>>
>> </ul>
>> ----------------------------------------------
>>
>> The above code loads in the template file, eval()'s it and then saves the
>> result into a variable, so that it may be intergraed into anouther element
>> of a dynamic website, which is a hell of a lot cleaner than the:
>> ----------------------------------------------
>> echo ("<something>" . $some_variable . "<something_else>"
>> ...);
>> ----------------------------------------------
>>
>> mess that you find in a lot of PHP code. Not only is it hard to read, but it
>> also produces awfully indented HTML, unlike the template method which outputs
>> properly indented code and is much easier to read.
>>
>> This works perfectly so long as output buffering is enabled, however for some
>> reason my web host has decided to disable output buffering in the config
>> file,
>> rendering the above elegant solution completely useless(*). So, why does PHP
>> have to have such a pain in the a$$ configuration file. It makes developing
>> platform and even install independent code a nightmare, I am seriously
>> considering
>> moving to a different language because of this.
>
> Could you tell us what configuration setting they have changed? I wasn't
> aware you could prevent the use of output buffering. I guess maybe if
> they set output_buffering = 1 to force flushing after a single byte.
> Either way, this is not a PHP issue, this is a web host problem. The
> blame lies squarely on their shoulders if they have changed how
> something fairly standard works. Such settings are usually made
> available to people who know what they're doing and who need specific
> functionality.
>
> Cheers,
> Rob.
In addition to what Rob said, the only other option would be
implicit_flush, which is ridiculous if it is set to on.
Maybe the file that you're evaling has some ob stuff or flush() in it?
--
Thanks!
-Shawn
http://www.spidean.com