PHP 5 installed locally doesn't read classes?

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
MikeM
Forum Newbie
Posts: 5
Joined: Thu Jan 25, 2007 11:09 pm

PHP 5 installed locally doesn't read classes?

Post by MikeM »

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]


Hello everyone,
For the first time, I installed PHP 5 and Apache on my windows xp machine.

Everything worked fine except for classes..which php seems to spit out as text.

Are there any known issues , or did I miss something in the php.ini file?

Here's the code I'm *trying* to use:

Code: Select all

class Page
{
  var $page;

  function Page($template = "template.html") {
    if (file_exists($template))
      $this->page = join("", file($template));
    else
      die("Template file $template not found.");
  }

  function parse($file) {
    ob_start();
    include($file);
    $buffer = ob_get_contents();
    ob_end_clean();
    return $buffer;
  }

  function replace_tags($tags = array()) {
    if (sizeof($tags) > 0)
      foreach ($tags as $tag => $data) {
        if (substr($data, 0, 3) == 'inc') { $data = substr($data, 3, strlen($data)); $data = (file_exists($data)) ? $this->parse($data) : $data; }
        $this->page = ereg_replace("{" . $tag . "}", $data,
                      $this->page);
        }
    else
      die("No tags designated for replacement.");
  }

  function output() {
    echo $this->page;
  }
}
Any help or input would be greatly appreciated :)


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
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Is this the whole file, in its entirety, without tags or anything else? Did you include() this file?
MikeM
Forum Newbie
Posts: 5
Joined: Thu Jan 25, 2007 11:09 pm

Post by MikeM »

Nevermind lol, I forgot to enable shorthand tags in the ini file, so everything between <? and ?> was read as text.

I guess I should look into the obvious reasons before asking for help.

Oh and sorry for not reading the posting guidelines, usually I check the sticky first.. forgot to do that.

Thanks again, Mike.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Short tags are bad.
MikeM
Forum Newbie
Posts: 5
Joined: Thu Jan 25, 2007 11:09 pm

Post by MikeM »

I know, I'm gonna go through and get rid of them.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

And hopefully you have already went back and disabled them so you know exactly where you need to fix stuff. While you are in there make sure register_globals is off.
MikeM
Forum Newbie
Posts: 5
Joined: Thu Jan 25, 2007 11:09 pm

Post by MikeM »

Globals is when php turns $_GET[somevariable] into $somevariable right?

Why would I wanna turn those off? :?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Because those are bad too. It makes lazy programmers, and it can be turned off on servers as well. If you write your code such that you assume they are off, your code will be more portable. However, you should still initialized the variables.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

MikeM wrote:Globals is when php turns $_GET[somevariable] into $somevariable right?

Why would I wanna turn those off? :?
Because they are horribly insecure and not portable.
MikeM
Forum Newbie
Posts: 5
Joined: Thu Jan 25, 2007 11:09 pm

Post by MikeM »

oh...ok then. Thanks for the tip 8)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

You know, an easy, sensible way to turn $_GET[somevariable] into $somevariable is

Code: Select all

$somevariable = "";
if(isset($_GET['somevariable'])) $somevariable = $_GET['somevariable'];
Try getting an error with that baby! :D
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

superdezign wrote:You know, an easy, sensible way to turn $_GET[somevariable] into $somevariable is

Code: Select all

$somevariable = "";
if(isset($_GET['somevariable'])) $somevariable = $_GET['somevariable'];
Try getting an error with that baby! :D
Why not use the braces? If you are going to write it like that, just use ternary...

Code: Select all

<?php
$getvar = isset($_GET['var']) ? $_GET['var'] : '';
?>
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Everah wrote: Why not use the braces? If you are going to write it like that, just use ternary...

Code: Select all

<?php
$getvar = isset($_GET['var']) ? $_GET['var'] : '';
?>
*Gasp* I did not know php supported that. 8O
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Learning new stuff every day...
Post Reply