Uploaded image for project: 'phpBB3'
  1. phpBB3
  2. PHPBB3-9682

Add a class loader for auto loading and define naming rules for new phpbb classes

    Details

    • Type: Task
    • Status: Unverified Fix
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 3.1.0-dev
    • Fix Version/s: 3.1.0-a1
    • Component/s: Other
    • Labels:
      None

      Description

      Since we are going to use object orientation a lot more, we naturally have more class definitions, which will not always need to be loaded. Autoloading provides a simple yet sufficiently efficient mechanism to avoid many conditional file inclusions. To use autoloading a convention for naming class needs to be established.

        Activity

        Hide
        naderman Nils Adermann added a comment -

        Implementation has been discussed on area51: http://area51.phpbb.com/phpBB/viewtopic.php?f=84&t=33237

        Show
        naderman Nils Adermann added a comment - Implementation has been discussed on area51: http://area51.phpbb.com/phpBB/viewtopic.php?f=84&t=33237
        Hide
        nickvergessen Joas Schilling added a comment -

        There's a little problem:

        I added a folder called gallery/ inside the includes/ dir.
        inside this dir I have several classes, but the phpbb_gallery class is not inside of it.

        now when I call phpbb_gallery I get:

        [phpBB Debug] PHP Notice: in file /includes/class_loader.php  on line 118: Undefined offset: 1


        the problem is the for-line

        		for ($i = 0; is_dir($path_prefix . $dirs . $parts[$i]) && $i < sizeof($parts); $i++)
        		{
        			$dirs .= $parts[$i] . '/';
        		}

        it tries to check whether the dir includes/gallery/$parts['1'] exists, before it compares the $i (1) to the sizeof (1) which means that it wouldn't go inside the loop anyway.

        The debug disappears, when you switch the two comparisons:

        		for ($i = 0; $i < sizeof($parts) && is_dir($path_prefix . $dirs . $parts[$i]); $i++)
        		{
        			$dirs .= $parts[$i] . '/';
        		}

        Show
        nickvergessen Joas Schilling added a comment - There's a little problem: I added a folder called gallery/ inside the includes/ dir. inside this dir I have several classes, but the phpbb_gallery class is not inside of it. now when I call phpbb_gallery I get: [phpBB Debug] PHP Notice: in file /includes/class_loader.php on line 118: Undefined offset: 1 the problem is the for-line for ($i = 0; is_dir($path_prefix . $dirs . $parts[$i]) && $i < sizeof($parts); $i++) { $dirs .= $parts[$i] . '/'; } it tries to check whether the dir includes/gallery/$parts ['1'] exists, before it compares the $i (1) to the sizeof (1) which means that it wouldn't go inside the loop anyway. The debug disappears, when you switch the two comparisons: for ($i = 0; $i < sizeof($parts) && is_dir($path_prefix . $dirs . $parts[$i]); $i++) { $dirs .= $parts[$i] . '/'; }
        Hide
        bantu Andreas Fischer added a comment -

        Yes, those two statements should be swapped. sizeof($parts) also doesn't seem to change in the loop, which means a variable should be used as per our coding guidelines. "$i+" could be "+$i" but that is tiny tiny tiny.

        Show
        bantu Andreas Fischer added a comment - Yes, those two statements should be swapped. sizeof($parts) also doesn't seem to change in the loop, which means a variable should be used as per our coding guidelines. "$i+ " could be " +$i" but that is tiny tiny tiny.
        Hide
        naderman Nils Adermann added a comment -

        Fixed that condition in my branch and added a test for it.

        Show
        naderman Nils Adermann added a comment - Fixed that condition in my branch and added a test for it.

          People

          • Assignee:
            naderman Nils Adermann
            Reporter:
            naderman Nils Adermann
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development