KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Help Debugging - "Illegal string offset 'TotalEst' #2135

Closed paulo opened this topic on on Jun 8, 2021 - 8 comments

paulo commented on Jun 8, 2021

I am receiving the following error, can you please help me debugging this

'"Illegal string offset 'TotalEst' (View: /home/forge/dev.ellisontravel.com/resources/views/report.blade.php)"'

I ran the query and didn't see any issue using MySQL. So no idea where to go from here thank you

"TotalEst"=>array(

                "cssStyle"=>"text-align:right",
                "type"=>"number",
                "decimals"=>2,
                "footer"=>"sum",
                "formatValue"=> function($value,$row) {
                    if ($row!=null) {
                        // $tourID = $value; // or = $row["tourid"];
                        $tourID = $row["TotalEst"];
                        $tourName = $row["paid_on"];
                        $color = $tourID >= $tourName ? "color:#718c00" : "color:#FF0000;font-weight: bold; ";
                        return "<span style='$color'>$" . number_format($value,2) . "</span>";
                    } else                        {
                        return "<span style='color:#718c00'>$" . number_format($value,2) . "</span>";
                    }
                },
            ),
Sebastian Morales commented on Jun 9, 2021

It meant your datasource/datastore had no column named "TotalEst". Please make sure the name is correct case-sensitively and use the following command in your report's view to see all columns of a datastore's data:

    //MyReport.view.php
    print_r($this->dataStore("myDatastore")->data());
paulo commented on Jun 10, 2021

thanks a lot. I used dd dd($this->dataStore("PlannerGoalsFile")->data()); All rows have this column, some with zeros, one with amount, another a negative amount. spelling and everything else seems correct. See full code at the bottom could this be an issue/bug when retrieving the value $tourID = $row["TotalEst"]; ? thank you "Illegal string offset 'TotalEst' (View: C:\dev\ellison-travel\resources\views\report.blade.php)" Column result using dd "TotalEst" => 24123.608 "TotalEst" => -581.8 "TotalEst" => 0.0

"TotalEst"=>array(

                "cssStyle"=>"text-align:right",
                "type"=>"number",
                "decimals"=>2,
                "footer"=>"sum",
                "formatValue"=> function($value,$row) {
                    if ($row!=null) {
                        // $tourID = $value; // or = $row["tourid"];
                        $tourID = $row["TotalEst"];
                        $tourName = $row["paid_on"];
                        $color = $tourID >= $tourName ? "color:#718c00" : "color:#FF0000;font-weight: bold; ";
                        return "<span style='$color'>$" . number_format($value,2) . "</span>";
                    } else                        {
                        return "<span style='color:#718c00'>$" . number_format($value,2) . "</span>";
                    }
                },
            ),
Sebastian Morales commented on Jun 11, 2021

Pls post the entire error's stack trace including the code line where it happens. Tks,

paulo commented on Jun 15, 2021

C:\dev\ellison-travel\app\Reports\Managers\PlannerGoals.view.php

                   // $year   = $row['goal_year'];
                    return number_format($tourID,2)."<br/>".number_format($tourName,2);
                },
            ),

            "tour_difference"=>array(
                "cssStyle"=>"text-align:right",
                "type"=>"number",
                "decimals"=>2,
                "footer"=>"sum",
            ),
            "TotalEst"=>array(
                "cssStyle"=>"text-align:right",
                "type"=>"number",
                "decimals"=>2,
                "footer"=>"sum",
                "formatValue"=> function($value,$row) {
                    if ($row!=null) {
                        // $tourID = $value; // or = $row["tourid"];
                        $tourID = $row["TotalEst"];
                        $tourName = $row["paid_on"];
                        $color = $tourID >= $tourName ? "color:#718c00" : "color:#FF0000;font-weight: bold; ";
                        return "<span style='$color'>$" . number_format($value,2) . "</span>";
                    } else                        {
                        return "<span style='color:#718c00'>$" . number_format($value,2) . "</span>";
                    }
                },
            ),
            "Balance"=>array(
                "cssStyle"=>"text-align:right",
                "type"=>"number",
                "decimals"=>2,
                "footer"=>"sum",
                "formatValue"=> function($value,$row) {
                    if ($row!=null) {
                        // $tourID = $value; // or = $row["tourid"];
                        $tourID = $row["Balance"];
                        $tourName = $row["paid_on"];
                        $color = $tourID >= $tourName ? "color:#718c00" : "color:#FF0000;font-weight: bold; ";
                        return "<span style='$color'>$" . number_format($value,2) . "</span>";

Arguments "Illegal string offset 'TotalEst' (View: C:\dev\ellison-travel\resources\views\report.blade.php)"

Illuminate \ View \ ViewException (E_ERROR) Illegal string offset 'TotalEst' (View: C:\dev\ellison-travel\resources\views\report.blade.php) Previous exceptions Illegal string offset 'TotalEst' (0)

Illuminate\View\ViewException …\app\Reports\Managers\PlannerGoals.view.php212 60 ErrorException …\app\Reports\Managers\PlannerGoals.view.php212 59 Illuminate\Foundation\Bootstrap\HandleExceptions handleError …\app\Reports\Managers\PlannerGoals.view.php212 52 koolreport\core\Widget create …\app\Reports\Managers\PlannerGoals.view.php126 50 koolreport\KoolReport render …\storage\framework\views\0059aefddb22ab4e88c58d653352bd6c4a0113eb.php1 1 Illuminate\Foundation\Http\Kernel handle …\public\index.php55

Environment & details: GET Data empty POST Data empty Files empty Cookies _ga "GA1.1.1325204529.1589334164" _spva_id_1fff "718434c0-84bf-469f-ba95-568ebe928aa0.1589334165.1.1589334165.1589334165.77644c4b-7756-4836-8745-9ea21497414a" ipe_s "f2a9b65e-26f3-b99f-bd88-ed413293c400" prevPageName "[[B]]" XSRF-TOKEN "eyJpdiI6InlUY3crMWdzblIyVmVNTnhha3hOTnc9PSIsInZhbHVlIjoiTHFHVWFNQXZybUdCbGxSaGlLclQ4ZkdWeWtIbHpoN1RLaHNuaFlHVWtuYkpKV1kwcTJDMnFOVG5Fb2d1VGNwSlhEbm13QmNUTWZQYVls ▶" atlaslocal_session "eyJpdiI6Ik9ieENScDh3Tmp3OTN2dEg3eFdFOXc9PSIsInZhbHVlIjoiaVlrbU5ZZVFMTWp4Um9ZWHR6REE1R3JmaGF6NmNkWjdqdXhXbDRTY05vREc4RjVPMm56RGxVVG5GYnFWVlA0S0hWVnk4VXMra25GRDly ▶" Session empty Server/Request Data DOCUMENT_ROOT "C:\dev\ellison-travel\public" REMOTE_ADDR "127.0.0.1" REMOTE_PORT "59823" SERVER_SOFTWARE "PHP 7.4.11 Development Server" SERVER_PROTOCOL "HTTP/1.1" SERVER_NAME "127.0.0.1" SERVER_PORT "8000" REQUEST_URI "/report/executeReport/Reporting:PlannerGoals" REQUEST_METHOD "GET" SCRIPT_NAME "/index.php" SCRIPT_FILENAME "C:\dev\ellison-travel\public\index.php" PATH_INFO "/report/executeReport/Reporting:PlannerGoals" PHP_SELF "/index.php/report/executeReport/Reporting:PlannerGoals" HTTP_HOST "localhost:8000" HTTP_CONNECTION "keep-alive" HTTP_CACHE_CONTROL "max-age=0" HTTP_SEC_CH_UA "" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"" HTTP_SEC_CH_UA_MOBILE "?0" HTTP_UPGRADE_INSECURE_REQUESTS "1" HTTP_USER_AGENT "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36" HTTP_ACCEPT "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9" HTTP_SEC_FETCH_SITE "same-origin" HTTP_SEC_FETCH_MODE "navigate" HTTP_SEC_FETCH_USER "?1" HTTP_SEC_FETCH_DEST "document" HTTP_REFERER "http://localhost:8000/report/myreports?search=goal" HTTP_ACCEPT_ENCODING "gzip, deflate, br" HTTP_ACCEPT_LANGUAGE "en-US,en;q=0.9,pt;q=0.8" HTTP_COOKIE "_ga=GA1.1.1325204529.1589334164; _spva_id.1fff=718434c0-84bf-469f-ba95-568ebe928aa0.1589334165.1.1589334165.1589334165.77644c4b-7756-4836-8745-9ea21497414a; ipe ▶" REQUEST_TIME_FLOAT 1623791012.1041 REQUEST_TIME 1623791012 Environment Variables empty Registered Handlers 0. Whoops\Handler\PrettyPageHandler

Sebastian Morales commented on Jun 16, 2021

Pls replace these lines of yours:

                        $tourID = $row["TotalEst"];
                        $tourName = $row["paid_on"];
                        $color = $tourID >= $tourName ? "color:#718c00" : "color:#FF0000;font-weight: bold; ";
                        return "<span style='$color'>$" . number_format($value,2) . "</span>";  

with these ones:

                        $tourID = $row["TotalEst"] ?? "TotalEst doens't exist or is null";
                        $tourName = $row["paid_on"];
                        $color = $tourID >= $tourName ? "color:#718c00" : "color:#FF0000;font-weight: bold; ";
                        return $tourID . "<span style='$color'>$" . number_format($value,2) . "</span>"; 

Then run your report and let us know the result. Tks,

paulo commented on Jun 16, 2021

Thank you, I had to replace few lines with the above otherwise the ' "Illegal string offset '' would just move to the next field. I had to change

 $tourID = $row["TotalEst"] ?? "TotalEst doens't exist or is null";
                        $tourName = $row["paid_on"]?? "paid_on doens't exist or is null";;

and then another column called Balance $tourID = $row["Balance"]?? "Balance doens't exist or is null";

                        $tourName = $row["paid_on"]?? "paid_on2 doens't exist or is null";

At least report is running now, but when I go to the bottom / total it will show 'TotalEst doens't exist or is null' based on the line you provided. everything else including values in the columns seem to be fine.

Please note this error only shows if I enter your line, If I replace with mine: return "<span style='$color'>$" . number_format($value,2) . "</span>"; but keeping $tourID = $row["TotalEst"] ?? "TotalEst doens't exist or is null"; it seems to be working and showing totals without any issue ?? it will show all the values and total at the bottom!

Also, If I add the following line will show the overall total without any problem.
TotalEst <?php echo number_format($this->dataStore('PlannerGoalsFile')->sum("TotalEst"),2); ?>

I am still now clear why this issue is happening and why I need "TotalEst doens't exist or is null"; - I will play at some point with Map to avoid having these things at the view level.

Is there anything I can do to fix this issue permanently / avoid future errors? Do you advise to just keep the line ?? "TotalEst doens't exist or is null"; for now?

thank you

Sebastian Morales commented on Jun 16, 2021

For now pls replace this line:

    $tourID = $row["TotalEst"] ?? "TotalEst doens't exist or is null";

with this:

    $tourID = $row["TotalEst"] ?? "";

I think this happens because some data rows (not all) from your data source lack the index "TotalEst". A good way to solve this is to use the Map process in your report's setup like this:

    ->pipe(new \koolreport\processes\Map(array(
        "{value}" => function($row) {
            if (!isset($row["TotalEst"])) $row["TotalEst"] = 0; //or null, "", etc depending on your likes
            if (!isset($row["paid_on"])) $row["paid_on"] = 0; 
            return $row;

This makes sure these indexes exists for your Table, Chart, etc in report's view. Rgds,

paulo commented on Jun 16, 2021

thanks a lot. I am planning to eventually move everything over to Map so the view is just a display and will list all columns. Thank you ! Paulo

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None