Results 1 to 7 of 7
Thread: Switch Function Problem
-
06-16-2004, 10:56 AM #1Web Hosting Guru
- Join Date
- Aug 2003
- Location
- PA
- Posts
- 303
Switch Function Problem
Im having problems with this switch function. When it goes to default i get this:
Fatal error: Call to a member function on a non-object in /home/user/public_html/test.phtml on line 32
PHP Code:<?php
require ('functions.php');
$id = $_GET['page'];
$site = new Page;
switch ($id){
case 'about_us':
$this->about_us();
break;
default:
$this->home();
break;
function home()
{
global $site;
$site -> head();
$site -> body();
$site -> loginform();
$site -> topmenu();
$site -> flashheader();
$site -> mainplans();
$site -> copyrights();
$site -> footer();
}
}
exit;
?>
-
06-16-2004, 11:55 AM #2Newbie
- Join Date
- Sep 2003
- Posts
- 12
Put the function before the switch statement.
-
06-16-2004, 12:02 PM #3Web Hosting Guru
- Join Date
- Aug 2003
- Location
- PA
- Posts
- 303
nope that didnt work. i get the same messege
-
06-16-2004, 12:13 PM #4Newbie
- Join Date
- Sep 2003
- Posts
- 12
Code:<?php require ('functions.php'); $id = $_GET['page']; $site = new Page; function home() { global $site; $site -> head(); $site -> body(); $site -> loginform(); $site -> topmenu(); $site -> flashheader(); $site -> mainplans(); $site -> copyrights(); $site -> footer(); } switch ($id){ case 'about_us': $this->about_us(); break; default: $this->home(); break; } ?>
-
06-16-2004, 12:13 PM #5WHT Addict
- Join Date
- Apr 2004
- Location
- Port St Lucie, FL
- Posts
- 117
First, I'd try to take the function out of the switch statement, and place it before the switch.
Second, do you really need the $this-> call? If you want to call the about_us method on the Page class, then you need to use $site instead of $this. Otherwise, you can just call about_us() without the $this. Same goes for home().
Good luck..Paul Embry
Knight Software and Web Design
Paul.Embry@gmail.com
Quality PHP Web Programming for Reasonable Prices
-
06-16-2004, 12:22 PM #6Web Hosting Guru
- Join Date
- Aug 2003
- Location
- PA
- Posts
- 303
Originally posted by nathank
Code:<?php require ('functions.php'); $id = $_GET['page']; $site = new Page; function home() { global $site; $site -> head(); $site -> body(); $site -> loginform(); $site -> topmenu(); $site -> flashheader(); $site -> mainplans(); $site -> copyrights(); $site -> footer(); } switch ($id){ case 'about_us': $this->about_us(); break; default: $this->home(); break; } ?>
-
06-16-2004, 12:26 PM #7Web Hosting Guru
- Join Date
- May 2004
- Location
- Singapore
- Posts
- 263
As mentioned:
1. Place the function outside the switch selection block.
2. Since you're not defining home() as a member function of a class, dont use it as such.
PHP Code:<?php
require 'functions.php';
function home(&$site)
{
$site->head();
$site->body();
$site->loginform();
$site->topmenu();
$site->flashheader();
$site->mainplans();
$site->copyrights();
$site->footer();
}
$site = &new Page;
if (!empty($_GET['page'])) {
switch ($_GET['page']) {
case 'about_us':
$site->about_us();
break;
default:
home($site);
}
}
exit;
?>#include<cstdio>
char*s="#include<cstdio>%cchar*s=%c%s%c;%cint main(){std::printf(s,10,34,s,34,10);}";
int main(){std::printf(s,10,34,s,34,10);}