1

我正在尝试'config.php'使用关联数组加载我的所有文件。不同的值表示可以找到文件的位置。但是我不断收到以下错误输出:

无法加载:array.php、array.php、array.php、array.php、dir.php、dir.php、dir.php、dir.php、auth.php、auth.php、auth.php、auth。 php,forms.php,forms.php,forms.php,forms.php,image.php,image.php,image.php,image.php,navigation.php,navigation.php,navigation.php,navigation.php, stats.php、stats.php、stats.php、stats.php、tables.php、tables.php、tables.php、tables.php、text.php、text.php、text.php、text.php、用户。 php,user.php,user.php,user.php,youtube.php,youtube.php,youtube.php,youtube.php,messages.php,messages.php,messages.php,messages.php,nemesis.php, nemesis.php、nemesis.php、nemesis.php、upload.php、upload.php、upload.php、upload.php、construct.php、construct.php、construct.php、construct.php、prepared_arrays.php、prepared_arrays。 php,prepared_arrays.php,prepared_arrays.php

我不确定为什么会发生这种情况,也不知道为什么它说文件无法加载 4 次。

<?php
    $require = array(
        'array.php' => 'f',
        'dir.php' => 'f',
        'auth.php' => 'f',
        'forms.php' => 'f',
        'image.php' => 'f',
        'navigation.php' => 'f',
        'stats.php' => 'f',
        'tables.php' => 'f',
        'text.php' => 'f',
        'user.php' => 'f',
        'youtube.php' => 'f',
        'messages.php' => 'c',
        'nemesis.php' => 'c',
        'upload.php' => 'c',
        'construct.php' => 't',
        'prepared_arrays.php' => 'l'
    );

    load($require);

    function load($require) {
        foreach ($require as $filename => $directory) {
            // init functions
            if ($directory = 'f') {
                $prep = FUNCTIONS_DIR . $filename;
                if (is_file($prep) && is_readable($prep)) {
                    require($prep);
                    $pass[] = $filename;
                } else {
                    $fail[] = $filename;
                }
            }
            // init classes
            if ($directory = 'c') {
                $prep = CLASSES_DIR . $filename;
                if (is_file($prep) && is_readable($prep)) {
                    require($prep);
                    $pass[] = $filename;
                } else {
                    $fail[] = $filename;
                }
            }
            // init templates
            if ($directory = 't') {
                $prep = TEMPLATES_DIR . $filename;
                if (is_file($prep) && is_readable($prep)) {
                    require($prep);
                    $pass[] = $filename;
                } else {
                    $fail[] = $filename;
                }
            }
            // init libs
            if ($directory = 'l') {
                $prep = LIBS_DIR . $filename;
                if (is_file($prep) && is_readable($prep)) {
                    require($prep);
                    $pass[] = $filename;
                } else {
                    $fail[] = $filename;
                }
            }
        }
        if (!empty($fail)) {
            if (!empty($pass)) {
                $passed  = implode(', ', $pass);
                $message = "Loaded: {$passed}";
                echo $message;
            }
            if (!empty($fail)) {
                $failure = implode(', ', $fail);
                $message = "Could not load: {$failure}";
                echo $message;
            }
            exit();
        }
    }
    ?>
4

1 回答 1

4

$directory = 'l' 应该是 $directory == 'l' :)

PS同样适用于您的所有比较。它们是比较,而不是分配。

于 2013-07-05T16:47:40.930 回答