Wednesday, April 20, 2011

PHP arrow operator closing tags

I am writing a php app on the websever I set up at my house. It is a fedora10 machine, running php5 and mysql. I have code like this:

<?php echo $var->function(); ?>

But for some reason the -> is closing the php tag, so the output has 'function(); ?' added to it...is there something I need to change in my php or webserver configuration?

From stackoverflow
  • I dont think that you have mod_php enabled in your apache config file, or else you would never see the php code in the output. Here is a good tutorial on setting up php 5 in apache.

    Schnalle : i think, shane is right. the php code is interpreted as html. in your source you should see the php-code 1 by 1 - nothing is interpreted. the `function()` is displayed because `` act as html-open and -close tags.
  • Try

    <?php echo("foo"); ?>
    

    If that doesn't work, you don't have PHP enabled in Apache.

    W_P : yes, php is enabled, I have been using it for a while, just never with any 'OO' php stuff before
  • If your're sure that php is enabled, try this one

    <?php
    $result = $var -> function();
    echo $result;
    ?>
    

    to debug it a little.. maybe something interesting will raise

  • Is the php enabled on server? A simple test for determining it:

    <?php phpinfo();?>

    Put the above line in a .php file and access it.

  • You could also try this:

    <?php phpinfo();
    

    Final closing php tag isn't required.

  • I ran into a similar problem the other day but I was using bar ?> instead of bar; ?>

    It turned out that the short_open_tag option was disabled in my PHP configuration.

  • I had the same problem with a standard XAMPP installation. short_open_tag=On solved it.

0 comments:

Post a Comment