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.

(*) This could be implemented by saving the variables as XML, making a POST
request to another script, which would then convert the XML back into an
array, eval() the template and send the result back to the first script
`as if' it was sending to a browser. The first script would then capture
the result as a variable. While this would also work, it would be unnecessary
complicated and very slow in comparison, It is *still* dependent on the
settings
in the config file.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to