Home > database >  Intellij Ultimate is not recognizing require function
Intellij Ultimate is not recognizing require function

Time:07-23

I have defined $names in index.php and you can see with the error below that it is not understanding the 'required' function. This only happens in intellij ultimate and works fine in Atom.

--index.php <?php

$names = [
    'Jeff',
    'Steve',
    'AJ'

];

require 'index.view.php';

--index.view.php

<html lang="en">
<head>

    <meta charset="UTF-8">

    <title>Document</title>

    <style>

        header {

            background: #e3e3e3;

            padding: 2em;

            text-align: center;
        }

    </style>

</head>
<body>

<ul>

    <?php
    foreach ($names as $name ) {

        echo "<li>$name</li>";
    }

    ?>

</ul>
</body>
</html>

This is the error it gives:

Warning: Undefined variable $names in C:\Users\ajmar\Desktop\php-learning\index.view.php on line 30

Warning: foreach() argument must be of type array|object, null given in C:\Users\ajmar\Desktop\php-learning\index.view.php on line 30

CodePudding user response:

The error message means that you are trying to run file index.view.php, which does now "know" about $names variable. You are OK to run index.php, because it has everything in place.

  • Related