ZF2 Uncaught Error:Class 'ArrayUtils' not found in E:\Temp\htdocs\zf-tutorial\public\index.php:43

345 views Asked by At

I am new at Zend2 and i am following the Album tuturial on Zend. I get the following error:

Fatal error: Uncaught Error: Class 'ArrayUtils' not found in E:\Temp\htdocs\zf-tutorial\public\index.php:43 Stack trace: #0 {main} thrown in E:\Temp\htdocs\zf-tutorial\public\index.php on line 43

I can't find whats the problem, what do i do wrong? Do i miss some code? Or do i miss some rules in the tutorial? here is my index.php file

   <?php

    use Zend\Mvc\Application;

    /**
     * Display all errors when APPLICATION_ENV is development.
     */
    if ($_SERVER['APPLICATION_ENV'] === 'development') {
        error_reporting(E_ALL);
        ini_set("display_errors", 1);
    }

    /**
     * This makes our life easier when dealing with paths. Everything is relative
     * to the application root now.
     */
    chdir(dirname(__DIR__));

    // Decline static file requests back to the PHP built-in webserver
    if (php_sapi_name() === 'cli-server') {
        $path = realpath(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
        if (__FILE__ !== $path && is_file($path)) {
            return false;
        }
        unset($path);
    }

    // Composer autoloading
    include __DIR__ . '/../vendor/autoload.php';

    if (! class_exists(Application::class)) {
        throw new RuntimeException(
            "Unable to load application.\n"
            . "- Type `composer install` if you are developing locally.\n"
            . "- Type `vagrant ssh -c 'composer install'` if you are using Vagrant.\n"
            . "- Type `docker-compose run zf composer install` if you are using Docker.\n"
        );
    }

    // Retrieve configuration
    $appConfig = require __DIR__ . '/../config/application.config.php';
    if (file_exists(__DIR__ . '/../config/development.config.php')) {
        $appConfig = ArrayUtils::merge($appConfig, require __DIR__ . '/../config/development.config.php');
    }

    // Run the application!
    Application::init($appConfig)->run();
1

There are 1 answers

1
gsc On BEST ANSWER

To be able to use the Zend\Stdlib\ArrayUtils class, you have to either:

  • add a use statement at the top of your file: use Zend\Stdlib\ArrayUtils; or
  • change your ArrayUtils invocation to Zend\Stdlib\ArrayUtils