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

(This post was last modified: 11-23-2020, 01:05 PM by Knutsford.)

(11-23-2020, 12:53 PM)InsiteFX Wrote: 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.

Yep I know Sad

So I jsut need to wrap objectToArray() around $row then when I assign it and it will work? That was where I was stuck. Thanks
Reply


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



Theme © iAndrew 2016 - Forum software by © MyBB