Page 1 of 1
Define classes inside of if/else?
Posted: Mon Mar 31, 2008 9:17 am
by JAB Creations
Is there a way I can set a class within an if/else? It's a rare option and I'd like to reduce server load by encasing it in an if/else...
Code: Select all
$my_class->set('something',$something);
Re: Define classes inside of if/else?
Posted: Mon Mar 31, 2008 10:11 am
by Christopher
Code: Select all
if ($i_want_my_class == true) {
include 'myclass.php';
}
Re: Define classes inside of if/else?
Posted: Mon Mar 31, 2008 10:40 am
by JAB Creations
So I have to create a separate class file? There is no way to do this in a single file?
Re: Define classes inside of if/else?
Posted: Mon Mar 31, 2008 10:45 am
by onion2k
Your first post doesn't explain what you're trying to do. If you want to selectively call the set() method, what's wrong with:
Code: Select all
if ($whatever_the_condition_is) {
$my_class->set('something');
} else {
$my_class->set($something);
}
Re: Define classes inside of if/else?
Posted: Mon Mar 31, 2008 11:09 am
by JAB Creations
Echo is PHP's alert for JavaScript and nothing is being echoed so here is more or less what I've tried....
file.php?thing=3
Code: Select all
class my_class {//class stuff here}
$settings = new settings();
if ($_GET['thing'] == "0") {$the_thing = 0;}
else if ($_GET['thing'] == "1") {$the_thing = 1;}
else if ($_GET['thing'] == "2") {$the_thing = 2;}
else if (isset($_GET['thing'])) {$error = thing;}
if (isset($error)) {
$settings->set('error',$error);
}
else {
$settings->set('error',$error);
}
...and nothing gets echoed....
Code: Select all
<?php
echo $settings->get('error');
echo $echoerror;
?>
Re: Define classes inside of if/else?
Posted: Mon Mar 31, 2008 12:50 pm
by JAB Creations
Realization!
I just realized I was doing...
if ($_GET
else if ($_GET
else if ($_GET
else if ($_COOKIE
else if (isset($_GET
I had my procedural programming not correctly set so even
if an unexpected get occurred the cookie already existed.
So problem solved.
