Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array

This is my first PHP project using Apache NetBeans.  I've been a casual Basic, C# and .NET programmer since 1983.  Spent most of my life coding with notepad/ftp, and I've just started using IDEs.

I am following instructions on this page to produce a simple drop down:
https://help.syncfusion.com/php/dropdownlist/getting-started

I keep getting the error in the subject line.  When Googled, I don't see anyone with my exact error, which leads me to believe it's a newb environmental mistake.

Here is my code:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
         <link rel='nofollow' href="http://cdn.syncfusion.com/20.2.0.43/js/web/flat-azure/ej.web.all.min.css" rel="stylesheet" />
         <link rel='nofollow' href="http://cdn.syncfusion.com/20.2.0.43/js/web/responsive-css/ej.responsive.css" rel="stylesheet" />
         <script src="http://cdn.syncfusion.com/js/assets/external/jquery-3.0.0.min.js"></script>
         <script src="http://cdn.syncfusion.com/js/assets/external/jsrender.min.js"></script>
         <script src="http://cdn.syncfusion.com/20.2.0.43/js/web/jquery-1.7.1.js"></script>
    </head>
    <body>
        <div class='cols-sample-area'>

<?php $items = array( array('text'=> 'ListItem 1'), array('text'=> 'ListItem 2'), array('text'=> 'ListItem 3'), array('text'=> 'ListItem 4'), array('text'=> 'ListItem 5'), ); $dropdownlist =new EJ\DropDownList('items'); $fields = new EJ\DropDownList\Field(); $fields->text('text'); echo $dropdownlist->AddItem($fields)->dataSource($items)->render(); ?>
    </div>
        <style>
            .cols-sample-area
            {
                width: 300px;
                margin: 0 auto;
                float: none;
            }
        </style>
    </body>
</html>

The exact error I get is:

Fatal error: Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, EJ\DropDownList given in C:\Users\martin\Documents\NetBeansProjects\CryptoVerify\EJ\Serialize.php:20 Stack trace: #0 C:\Users\martin\Documents\NetBeansProjects\CryptoVerify\EJ\Serialize.php(20): array_key_exists('item', Object(EJ\DropDownList)) #1 C:\Users\martin\Documents\NetBeansProjects\CryptoVerify\EJ\DropDownList\DropDownList.php(371): EJ\Serialize->add('item', Array) #2 C:\Users\martin\Documents\NetBeansProjects\CryptoVerify\index.php(32): EJ\DropDownList->addItem(Object(EJ\DropDownList\Field)) #3 {main} thrown in C:\Users\martin\Documents\NetBeansProjects\CryptoVerify\EJ\Serialize.php on line 20

All EJ files are in a folder called EJ.

Thanks so much!

Martin


1 Reply

IL Indhumathy Loganathan Syncfusion Team October 14, 2022 12:45 PM UTC

Hi Martin,


Greetings from Syncfusion support.


We have validated your reported query with the shared details. The reported issue occurs due to the missing AutoLoad.php file in the shared code. Also, you missed adding the script reference in your code. Check the modified code below.


<!DOCTYPE html>

<html>

    <head>

        <meta charset="UTF-8">

        <title></title>

         ...

     <script src=http://cdn.syncfusion.com/20.3.0.47/js/web/ej.web.all.min.js></script>

    </head>

    <body>

   <?php require_once 'EJ/AutoLoad.php'; ?>

        <div class='cols-sample-area'>

         ...

    </body>

</html>


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DropdownListPHP-449168326


Documentation: https://help.syncfusion.com/php/getting-started#create-a-simple-php-application


Please check the attached sample and get back to us if you need any further assistance.


Regards,

Indhumathy L


Loader.
Up arrow icon