I had a general question on proper design of a php files and their storage on a server.
The problem is this: I had split a php object’s functions into different php files, something like:
File 1 AndroidFlashCard.php
class AndroidFlashCard {
public function retrieveCards($packname){}
public function retrievePacks(){}
....
File 2 RetrieveCards.php
include ($_SERVER['DOCUMENT_ROOT'].'/flash_card/AndroidFlashCard.php');
$connection = new AndroidFlashCard();
$connection->retrieveCards($_REQUEST['pack']);
...
Besides the bad code smell regarded making seperate php files for a single function calls, the problem happens when the location/name of class AndroidFlashCard changes. Suppose we go with this shoddy design and I have 1000 different functions…
The quick and dirty solution that came to mind was to have ANOTHER include file:
File 3 include.php:
include ($_SERVER['DOCUMENT_ROOT']./[location of class])
But this doesn’t really change anything, because if the location of the include.php file changes, I’d have to make 1000 changes again.
So let’s think about this. If I have to keep making 1000 changes to 1000 php files that only include a reference to a class and then code to execute a function, then maybe THAT is the design problem.
In android, I only know how to execute http requests, which is why I split the function calls into separate files.
If I could get hold of that php object, it would make things easier, but I’ve a feeling this will be difficult to accomplish.
What is the simpler solution? Is writing directory structures a design part of production work, which after approval, is simply just written in stone?
This sounds like a good case for class autoloading. When you attempt to use the class in say file 2, then php can call an autoload function to actually find the class to include. You will have to write the logic behind it, but thats 1 change rather then a 1000 as you say.
__autoload($class_name)