storing php5 classes and function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alamin Ahmed

    #1

    storing php5 classes and function

    what is the best way to store and call php classes written and
    submitted by other developers?

    let's say i want to do the following

    $obj = new $userclass();
    $obj->display($assoc _array);

    basically developers will have away to write different "print" method
    of given array. How and where would I store their class source fine
    and how would I load and use to display?

    Thanks!

  • macca

    #2
    Re: storing php5 classes and function

    Take a look at autoloading.



    e.g.

    function __autoload($cla ss_name) {
    require_once $class_name . '.php';
    }

    Comment

    • Dikkie Dik

      #3
      Re: storing php5 classes and function

      function __autoload($cla ss_name) {
      require_once $class_name . '.php';
      }
      One nice thing to notice: an included file can return a value, which may
      be an instance. So you could write a class in a file that looks like this:

      class WhatEver
      {
      ....
      }

      return new WhatEver();

      And then call that dynamically:

      $obj = require($pathTo WhatEver);

      I use this trick for my unit testing system.

      Comment

      • Ulf Kadner

        #4
        Re: storing php5 classes and function

        macca schrieb:
        Take a look at autoloading.
        >

        >
        e.g.
        >
        function __autoload($cla ss_name) {
        require_once $class_name . '.php';
        }
        Thats the bad way.

        Better to use spl_register_au toload() with userdefined autoload
        functions. So other developers are also able to use own autoloads.

        So long, Ulf

        Comment

        Working...