TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Function overloading for modular system? (http://www.talkphp.com/advanced-php-programming/4659-function-overloading-modular-system.html)

Jim 07-01-2009 06:11 PM

Function overloading for modular system?
 
Hi!

I'm about to create an open source gallery but I have some isues with the design of the system.

I have two classes which take care of image and folder handling. One to read a folder with items, and a class to represent an item.

http://minna-media.com/files/FiguraC...ram%20v1-1.png

But now I would like modular system for both the PathReader and Item. I was thinking about using __call, __get and __set. Of course this would making it modular pretty easy, but is this the best way to go?

I made allot of CMS etc, but in the end it never was 100% how I wanted it to be, so this time I want to plan it into its tinyest detail. :) (been thinking of the layout for the system for months already)

Enfernikus 07-01-2009 06:30 PM

Overloading in PHP simply involves not setting any arguments and calling func_get_args within the function.

Jim 07-01-2009 06:50 PM

I want to use it like this:

PHP Code:

class Foo 
{
  function 
__call($name$args)
  {
    if(
file_exists(MODULE_PATH '/' $name '.php';
    {
      require_once 
MODULE_PATH '/' $name '.php';
      
      
$mObj = new {$name}($args); // Dont know if this will work, but its about the idea
      
return $mObj->result(); 
    }
  }


This is some fast code, not how I would like to build it (e.g. I dont want to check if the module exists every time etc)

Enfernikus 07-01-2009 07:49 PM

Something along the lines of the Registry pattern will suit you but with the registry pattern you'll need to allow for the object to initiated first without any arguments and than pass them through.


All times are GMT. The time now is 09:19 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0