Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7959291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:33:01+00:00 2026-06-04T04:33:01+00:00

Hey guys I’m getting three things right now that I’m trying to take care

  • 0

Hey guys I’m getting three things right now that I’m trying to take care of, and hoping you can help. I have and error, a warning, and a notice in my code that I would like to patch up and am hoping that you can help me, errors are as follows.

There are the wonderful errors

PHP Warning:  Invalid argument supplied for foreach() in php/libraries/RotateLatestAssets.class.php on line 35
PHP Notice:   Undefined variable: config in php/libraries/RotateLatestAssets.class.php on line 18
PHP Notice:   Undefined variable: json in php/libraries/RotateLatestAssets.class.php on line 31
PHP Notice:   Undefined variable: json in php/libraries/RotateLatestAssets.class.php on line 32

And then there’s a really really weird one I comment out in my code….
I’m thinking gnomes, but who knows….

Here’s the class

<?php

class RotateLatestAssets
{
    protected   $config;

    public function __construct()
    {
        $this->config = $config;
    }

    //********************************************************************************
    //* Public Methods
    //********************************************************************************

    public function getAssets()
    {

        $this->json = self::jsonDecode($this->config, true);


        define('latest',    __DIR__ . $json['paths']['latest']);
        define('dist',      __DIR__ . $json['paths']['dist']);


        foreach($this->json['files'] as $fileName => $fileVersion)
        {
            $cacheName = implode("-$fileVersion.", explode('.',$fileName) );
            if(!file_exists(dist . $cacheName))
            {
                try {
                    copy(latest . $cacheName, dist . $fileName);
                } catch(Exception $e) {
                    echo 'Copy Exception: ',  $e->getMessage(), "\n";
                }
            }
        }

    }

    //********************************************************************************
    //* Static Methods
    //********************************************************************************

    /**
    * Returns a json decoded object or array
    *
    * @param    string  $json
    * @param    bool    $toAssoc
    * @return   object|array Depending on the parameter supplied
    */

    private static function jsonDecode($json, $toAssoc = true)
    {

        /** 
         * Based on known JSON_DECODE() errors
         * 0 = JSON_ERROR_NONE
         * 1 = JSON_ERROR_DEPTH
         * 2 = JSON_ERROR_STATE_MISMATCH
         * 3 = JSON_ERROR_CTRL_CHAR
         * 4 = JSON_ERROR_SYNTAX
         * 5 = JSON_ERROR_UTF8
         */

        $result = json_decode($json, $toAssoc);

        /*  Will produce this sometimes out of the blue after a few refreshes?

            PHP Fatal error:  Uncaught exception 'Exception' with message 
            'JSON Error:  - Syntax error, malformed JSON' in php/libraries/RotateLatestAssets.class.php:99

            Stack trace:
            #0 php/libraries/RotateLatestAssets.class.php(28): RotateLatestAssets::jsonDecode(NULL, true)
            #1 php/libraries/RotateLatestAssets.class.php(119): RotateLatestAssets->getAssets()
            #2 {main}
              thrown in php/libraries/RotateLatestAssets.class.php on line 99
        */

        switch(json_last_error())
        {
            case JSON_ERROR_DEPTH:
                $error =  ' - Maximum stack depth exceeded';
                break;
            case JSON_ERROR_STATE_MISMATCH:
                $error = ' - Invalid or malformed JSON encoding';
                break;
            case JSON_ERROR_CTRL_CHAR:
                $error = ' - Unexpected control character found';
                break;
            case JSON_ERROR_SYNTAX:
                $error = ' - Syntax error, malformed JSON';
                break;
            case JSON_ERROR_UTF8:
                $error = ' - Syntax error, malformed UTF-8 characters';
                break;
            case JSON_ERROR_NONE:
            default:
                $error = ''; 
        }

        if (!empty($error)) throw new Exception('JSON Error: '.$error);
        return $result; 
    }

    /**
    * Returns bool value for state of array recieved dev:(true) live:(false)
    *
    * @param    array   $array
    * @return   bool
    */

    private static function checkMode($array)
    {
        if(!is_array($array)) throw new Exception("Wrong Type Passed. Expecting (array), received (".gettype($array).")");
        return ($array['dev'] == 'true') ? true : false;
    }
}


$instance = new RotateLatestAssets($_SERVER['DOCUMENT_ROOT'].'build/config.json');
$instance->getAssets();

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:33:02+00:00Added an answer on June 4, 2026 at 4:33 am

    In your constructor, you have:

    $this->config = $config;
    

    Yet the $config variable is never created, so it has no value.

    You do the same thing in getAssets(). You use $json, but it has never been defined.

    The invalid argument error is because you are essentially doing foreach(null which is wrong, you can only iterate an array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys I can't seem to get the syntax here right, I'm just trying
Hey guys I'm tired and can't figure this one out so any help would
Hey guys can anybody help me with texture mapping in Direct3D C++. I have
Hey Guys, here is my code for this, the only help i get from
Hey guys i am trying to automate my system at work for sending artwork
Hey guys I was wondering if someone could provide a little help. I've been
Hey guys i have two date inputs containing three dropboxes for day,month and year
Hey guys I'm trying to add the string 'url( ) ' around my a
Hey guys, I'm trying to get my head around LINQ and FP, so forgive
Hey guys I just noticed that my join statement here SELECT * FROM reports

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.