Welcome Guest, Not a member yet? Register   Sign In
<p>Message: Cannot use object of type stdClass as array</p>
#2

Because you are trying to assign an object to an array.

I use these to helper when I need to convert one to the other.

PHP Code:
// -----------------------------------------------------------------------

if ( ! function_exists('objectToArray'))
{
    /**
     * objectToArray ()
     * -------------------------------------------------------------------
     *
     * @param  $data
     * @return array
     */
    function objectToArray(object $data) : array
    {
        if (is_object($data))
        {
            /**
             * Gets the properties of the given object
             * with get_object_vars function
             */
            $data get_object_vars($data);
        }

        /**
         * Return array converted to object Using __FUNCTION__ (Magic constant)
         * for recursive call
         */
        return (is_array($data)) ? array_map(__FUNCTION__$data) : $data;
    }
}

// -----------------------------------------------------------------------

if ( ! function_exists('arrayToObject'))
{
    /**
     * arrayToObject ()
     * -------------------------------------------------------------------
     *
     * @param  $data
     * @return object
     */
    function arrayToObject(array $data) : object
    
{
        /**
         * Return array converted to object Using __FUNCTION__ (Magic constant)
         * for recursive call
         */
        return (is_array($data)) ? (object) array_map(__FUNCTION__$data) : $data;
    }


Place these in one of your helpers and load it.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
RE: <p>Message: Cannot use object of type stdClass as array</p> - by InsiteFX - 11-23-2020, 12:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB