PHP stops handling my page every time it encounters >

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
BeauMN
Forum Newbie
Posts: 6
Joined: Fri Nov 24, 2006 5:20 pm

PHP stops handling my page every time it encounters >

Post by BeauMN »

Hi,
I'm new to PHP, but not to programming. I have installed the latest Apache server and the latest PHP as an Apache module. It works fine, but evertime there is a greater-than (>) symbol in my PHP code, PHP stops handling the code. I don't know why this is. I was under the impression that the > must be preceded by ? for this to happen. I need to use > in my PHP code so that I can have html tags in my calls to the echo() function.
Thanks,
Beau
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

Post by wtf »

post some code
BeauMN
Forum Newbie
Posts: 6
Joined: Fri Nov 24, 2006 5:20 pm

Post by BeauMN »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

<?php
      class Calendar
      {
        private $month=array();
        private $current=array();

        function __construct()
        {
         $month["name"] = "November"; $month["number"] = 30;
        }

        function Display()
        {
         echo '<table>';  //from here on everything after the > insn't executed by PHP
          echo '<tr>';
           for($i=0; $i<$month["number"]; i++)
           {
            echo '<td>';
             echo "<h2>$i</h2>";
            echo '</td>';
           }
          echo '</tr>';
         echo '</table>';
        }
      }

      $c = new Calendar();
      $c->Display();
    ?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

This has nothing to do with that operator, instead you have undefined variables, your loop isn't evaluating because $i will always be greater than nothing.
You would have been aware of this if you had error_reporting(E_ALL); set :wink:

Instead, you need to reference your class variables

Code: Select all

function __construct()
{
   $month["name"] = "November"; $month["number"] = 30;
}
These variables will only be accessible within that method. Try

Code: Select all

function __construct()
{
   $this->month["name"] = "November"; 
   $this->month["number"] = 30;
}
To bring the variables into class scope.. and obviously change the other instances of those variables accordingly.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Moved to PHP Code.
BeauMN
Forum Newbie
Posts: 6
Joined: Fri Nov 24, 2006 5:20 pm

Post by BeauMN »

Hmm, I just tried that, and now PHP stopped executing after the > in $this->
I'm pretty sure that it is the > operator that is messing things up for me. I tried the following code as a test:

Code: Select all

<?php
      echo "<p>Hello</p>";
      echo "<p>World</p>";
    ?>
When I do this, the output in my browser is the following:
Hello"; echo "

World
"; ?>
As you can see, PHP stops executing after the > operator, wherever it is found in the PHP code. I'm figuring this might be a problem with my server configuration, but have no clue how to fix it. I left the default install options for Apache and PHP, using the recommended php.ini file. The only changes I made to the default Apache configuration were to load PHP as a module.

Any ideas?
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Assuming that the simple hello world script is in-fact causing the problems, I would suspect a corrupted php installation... re-install php and the problem will probably go away...

as an aside, what version of php are you running (show us the top part of the phpinfo() output)
BeauMN
Forum Newbie
Posts: 6
Joined: Fri Nov 24, 2006 5:20 pm

Post by BeauMN »

Haha, okay, it was all my mistake from the beginning. I forgot to change the extensions on my pages to .php
They had been .html files

Sorry
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

BeauMN wrote:Haha, okay, it was all my mistake from the beginning. I forgot to change the extensions on my pages to .php
They had been .html files

Sorry
Happens to us all, take care.
Post Reply