faqts : Computers : Programming : Languages : PHP : kms : Classes

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

15 of 16 people (94%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

Can I put include or require inside a class definition?

Jun 14th, 1999 07:00
Nathan Wallace, Rod Kreisler


No.

You just can't put anything inside a class definition EXCEPT variable
and function definitions.

The following code is *not* legal:

    <?
    class Database {

      /* properties */
      var $db_path;
      var $db_id;
      var $db_fields;

      /* Services */
      require("open.inc");
      require("close.inc");

    }
    ?>


To clarify, the following code *does* work.  This because all we have in
the class are variable and function definitions; the require() is inside
the function definition for open().

    <?
    class Database {

      /* properties */
      var $db_path;
      var $db_id;
      var $db_fields;

      /* Services */
      function open($db_path,$access) {
          require("open.inc");
      }
    }
    ?>