Fatal error: Uncaught Error: Call to a member function get()

i get these errors, I went from 2020 to 2021

( ! ) Fatal error: Uncaught Error: Call to a member function get() on null in C:\wamp64\www\mws\src\phpfn.php on line 122
( ! ) Error: Call to a member function get() on null in C:\wamp64\www\mws\src\phpfn.php on line 122

Time Memory Function Location

1 0.0001 362624 {main}( ) …\index.php:0
2 0.0016 526384 require_once( ‘C:\wamp64\www\mws\src\userfn.php’ ) …\index.php:28
3 0.0016 526792 PHPMaker2021\fw\ExecuteRow( ) …\userfn.php:175
4 0.0016 526792 PHPMaker2021\fw\ExecuteQuery( ) …\phpfn.php:5658
5 0.0016 527112 PHPMaker2021\fw\Conn( ) …\phpfn.php:5488
6 0.0017 549224 PHPMaker2021\fw\ConnectDb( ) …\phpfn.php:1283
7 0.0018 550072 PHPMaker2021\fw\Container( ) …\phpfn.php:1370


userfn.php:175
$attiva = ExecuteRow(“SELECT idCampagna, Nome FROM campagne WHERE Attiva = ‘1’”);

so in 2021 the new calls are like this?
ExecuteScalar → ExecuteQuery()
ExecuteRow/S → ExecuteQuery()

  1. Regarding the error: https://discourse.hkvstore.com/t/call-to-a-member-function-get-on-null/3053/1
  2. Regarding the global functions:

I have checked but find no errors. The only thing is that I notice that unlike the 2020 version now in the golbal code it does not accept variables without function can it be?

phpfn.php
works fine
//Get active campaigns
function getActiveCamp(){
$ac = ExecuteScalar(“SELECT campagne.idCampagna FROM campagne WHERE campagne.Attiva = ‘1’”);//row 162
return $ac;
}
//Get all campaigns array
function getAllCamp(){
$alc = ExecuteRows(“SELECT idCampagna FROM campagne”);
$alc = implode(“,”, array_column($alc, “idCampagna”));
return $alc;
}

not works
//CurrentPageName() != “prospetto.php”
if (CurrentUserLevel() != -2){
//Get nome and status attiva campaing
$attiva = ExecuteRow(“SELECT idCampagna, Nome FROM campagne WHERE Attiva = ‘1’”);//row 175 error
//Get avvisi for menu bar
$status = ExecuteScalar(“SELECT COUNT(idTicket) FROM ticket WHERE Tipo = ‘2’ && Stato = ‘0’”);
}

GT73 wrote:

not works
//CurrentPageName() != “prospetto.php”

In v2021, for the example above, CurrentPageName() will return “prospetto”. In other words, it will not include the .php (extension file) anymore. (See Migrating to v2021: https://phpmaker.dev/doc/migrate2021.htm)

Thanks
I will have to change them all however this was in comment.
I tried to set them as global but it doesn’t work. I call the variable in the header

userfn.php (Global Code)
if (CurrentUserLevel() != -2){
//Get send email/sms for menu bar
$GLOBALS[‘em’] = ExecuteScalar(“SELECT SUM(LENGTH(Users) - LENGTH(REPLACE(Users, ‘,’, ‘’)) + 1) FROM messages WHERE Tipo = ‘1’ || TIPO = ‘3’”);
}

I’ve tried in page_loading but not works
// Page Loading event
function Page_Loading() {
if (CurrentUserLevel() != -2){
$GLOBALS[‘em’] = ExecuteScalar(“SELECT SUM(LENGTH(Users) - LENGTH(REPLACE(Users, ‘,’, ‘’)) + 1) FROM messages WHERE Tipo = ‘1’ || TIPO = ‘3’”);
}
}

Were you able to fix your issue ?

i got the same problem no matter what query i put in global code, if i do not put in a function it will throw an error

I deleted everything on global code and added this only $CID=ExecuteScalar("SELECT CI FROM mse WHERE MSID=‘56’ ");
and i get your similar error.

you can to doing in two ways:
Put the non function codes in Page_Loading and try again. Note that you need to define the global variables first in global codes then use $GLOBALS[“var”] to set up the variables.

  1. in Global Codes:
    $var = “”; // Define global variable
    in Page_Loading:
    global $var;
    $var = ExecuteScalar(…);

  2. in Global Codes:
    function MyFunction() {
    $var = ExecuteScalar(…);
    return $var;
    };
    In your header/footer ecc
    echo MyFunction()//if string
    echo MyFunction()[‘arraykey’]//if array

GT73 wrote:

you can to doing in two ways:
Put the non function codes in Page_Loading and try again. Note that you need to
define the global variables first in global codes then use $GLOBALS[“var”]
to set up the variables.

  1. in Global Codes:
    $var = “”; // Define global variable
    in Page_Loading:
    global $var;
    $var = ExecuteScalar(…);

  2. in Global Codes:
    function MyFunction() {
    $var = ExecuteScalar(…);
    return $var;
    };
    In your header/footer ecc
    echo MyFunction()//if string
    echo MyFunction()[‘arraykey’]//if array


    Thanks that is exactly how to proceed.