Use php files as functions?
Posted: Sun Dec 05, 2010 10:12 am
I will have a lot of function requirements, and instead of having one giant php file, was thinking about trying to have one main php file that has case statements and calls to other files that are acting like functions. There could be 50 or more functions.
I wanted to see if this is doable and something you guys consider good practice or bad.
This is oversimplified but the idea. A microprocessor sends out a string as needed to the dns to update the database like this:
string("main.php?OPCODE=1&PAR1=1, PAR2=2))
The main.php file would have a case statement:
What I can't find in any tutorials I have seen is how I can forward any paramters or have the result returned by a call to a file except by echo ie:
I wanted to see if this is doable and something you guys consider good practice or bad.
This is oversimplified but the idea. A microprocessor sends out a string as needed to the dns to update the database like this:
string("main.php?OPCODE=1&PAR1=1, PAR2=2))
The main.php file would have a case statement:
Code: Select all
<html>
<body>
<?php
switch ($x)
{
case '$_REQUEST[OPCODE]' ":
$file=fopen("1.php","r");
break;
case '$_REQUEST[OPCODE]':
$file=fopen("2.php","r");
break;
case '$_REQUEST[OPCODE]':
$file=fopen("3.php","r");
break;
}
?>
</body>
</html> Code: Select all
$file=fopen("3.php('$_REQUEST[PAR1]&'$_REQUEST[PAR2]')","r");