Page 1 of 1

PHP 5 installed locally doesn't read classes?

Posted: Thu Jan 25, 2007 11:14 pm
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]

Posted: Thu Jan 25, 2007 11:19 pm
by feyd
Is this the whole file, in its entirety, without tags or anything else? Did you include() this file?

Posted: Thu Jan 25, 2007 11:21 pm
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.

Posted: Thu Jan 25, 2007 11:25 pm
by feyd
Short tags are bad.

Posted: Thu Jan 25, 2007 11:27 pm
by MikeM
I know, I'm gonna go through and get rid of them.

Posted: Wed Jan 31, 2007 6:56 pm
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.

Posted: Wed Jan 31, 2007 7:51 pm
by MikeM
Globals is when php turns $_GET[somevariable] into $somevariable right?

Why would I wanna turn those off? :?

Posted: Wed Jan 31, 2007 9:29 pm
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.

Posted: Thu Feb 01, 2007 12:14 am
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.

Posted: Thu Feb 01, 2007 12:18 am
by MikeM
oh...ok then. Thanks for the tip 8)

Posted: Thu Feb 01, 2007 12:19 am
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

Posted: Thu Feb 01, 2007 12:23 am
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'] : '';
?>

Posted: Thu Feb 01, 2007 12:24 am
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

Posted: Thu Feb 01, 2007 1:21 am
by RobertGonzalez
Learning new stuff every day...