| | |
beginner question
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2007
Posts: 10
Reputation:
Solved Threads: 0
Hey I'm a php beginner and I'm having some problems with the website I'm testing with. I'll show you first the relevant code.
index.php:
stdlib.php:
Page.php:
The error I'm getting now that I've put in the autoload function is:
All of these files are in the same directory, so I'm not sure why it can't find the Page class. Anyone have an idea?
index.php:
php Syntax (Toggle Plain Text)
<?php include "stdlib.php"; $page = new Page(); $page->title = "Index"; $page->printHeader(); ?> <style type="text/css"> div.container { width:100%; margin:0px; border:1px solid gray; } div.left { width:100px; float:left; padding:1em; margin:0; } div.content { margin-left:190px; border-left:1px solid gray; padding:1em; } </style> <div class="container"> <div class="left"><p class="left">Seth Baur</p></div> <div class="content"> <p>Welcome to my site.</p> <?php echo date("d-m-Y"); ?> <form action="form.php" method="post"> Name: <input type="text" name="name" /><br /> Age: <input type="text" name="age" /><br /> <input type="submit" /> </form> </div> </div> <?php $page->printFooter(); ?>
stdlib.php:
php Syntax (Toggle Plain Text)
<?php function __autoload($class_name){ require_once $class_name . '.php'; } ?>
Page.php:
php Syntax (Toggle Plain Text)
<?php class Page { var $title; function printHeader() { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <link rel="stylesheet" type="text/css" href="styles.css" /> <title><?php echo $this->title; ?></title> </head> <body> <?php } function printFooter() { ?> </body> </html> <?php } } ?>
The error I'm getting now that I've put in the autoload function is:
PHP Syntax (Toggle Plain Text)
Fatal error: Cannot instantiate non-existent class: page in /home/content/t/h/r/threepio/html/seth/php/index.php on line 3
All of these files are in the same directory, so I'm not sure why it can't find the Page class. Anyone have an idea?
Last edited by sethbaur; Dec 16th, 2007 at 10:08 pm.
•
•
Join Date: Sep 2007
Posts: 10
Reputation:
Solved Threads: 0
buddylee17:
The variable $class_name is passed to the autoload function when the it comes to a class that is not defined. At that point it includes the class it couldn't find with ".php" appended on the end.
MickRip:
And yes I could replace stdlib.php with Page.php, but the idea is that this way, I could include many classes, in individual files, without "including" each.
The variable $class_name is passed to the autoload function when the it comes to a class that is not defined. At that point it includes the class it couldn't find with ".php" appended on the end.
MickRip:
And yes I could replace stdlib.php with Page.php, but the idea is that this way, I could include many classes, in individual files, without "including" each.
![]() |
Similar Threads
- C++ beginner's question (C++)
- A Basic Question. . . (Windows 95 / 98 / Me)
- C compiler help (beginner question) (C++)
- beginner needs help with game programming (Game Development)
- Beginner Networking (Networking Hardware Configuration)
Other Threads in the PHP Forum
- Previous Thread: url help
- Next Thread: page by page
| Thread Tools | Search this Thread |
.htaccess alerts apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database dataentry date display duplicates dynamic echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google hack href htaccess html htmlspecialchars image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching menu methods mlm multiple mysql network object oop paypal pdf php problem query radio random recursion recursive redirect remote script search securephp server sessions shot sms source space sql subscription syntax system table tutorial tutorials update upload url validator variable video web youtube





