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 9096253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:47:58+00:00 2026-06-16T23:47:58+00:00

I have a GCM class which includes a send_notification function. In a different class,

  • 0

I have a GCM class which includes a send_notification function. In a different class, Demand.php, I am trying to use the send_notification function. So I have a constructor in Demand.php which points to my GCM class like this:

 $gcm = new GCM();

This $gcm variable is used in a function inside that class like this:

$result = $gcm->send_notification($registatoin_ids, $message);

That’s where I get the error:

<br />n<b>Fatal error</b>:  Call to a member function send_notification() on a non-object in..

I searched for the problem and found out that the problem is that $gcm is null and that’s why it’s calling nothing. So when I put the

$gcm = new GCM();

Inside my function it worked correctly. But is there no other way of doing this? I mean should it not be alright only by putting creating $gcm in the constructor of Demand.php?

Here are the parts where I am referring to:

function __construct() {
    require_once 'GCM.php';
    require_once 'DB_Connect.php';
    require_once 'DB_Functions.php';
    // connecting to database
    $this->db = new DB_Connect();
    $this->db->connect();
    $gcm = new GCM();
    $df = new DB_Functions();

}

// destructor
function __destruct() {

}


public function getDistance($uuid, $name, $distance, $latstart, $lonstart, $latend, $lonend, $gcm_regId) {
    $user_new = array ("$uuid", "$name", "$distance","$latstart", "$lonstart", "$latend", "$lonend","$gcm_regId");  
    $query = sprintf("SELECT uid, distance,latstart, lonstart, latend, lonend, gcm_regid, name FROM user_demand WHERE latstart='%s' AND lonstart='%s'",
    mysql_real_escape_string($latstart),
    mysql_real_escape_string($lonstart));
    $user = mysql_query($query);

    $no_of_rows = mysql_num_rows($user);

    while($user_old = mysql_fetch_assoc($user))
    {
        $djson = $this->findDistance($latend,$lonend,$user_old["latend"],$user_old["lonend"] );

        if ($user_old["distance"]+$distance>=$djson) {
            $match = mysql_query("INSERT INTO matched_users(gcm_a, gcm_b, name_a, name_b) VALUES(".$user_old['gcm_regid'].",".$user_new['gcm_regId'].",".$user_old['name'].",".$user_new['name'].")");
            $registatoin_ids = array($gcm_regId);
            $message = array("var" => $name);
            $result = $gcm->send_notification($registatoin_ids, $message);
        }
    }
}
  • 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-16T23:48:00+00:00Added an answer on June 16, 2026 at 11:48 pm

    If you put $gcm = new GCM(); in the constructor of your Demand class, then the variable $gcm will only be available in the constructor method.

    If you want to be able to access the $gcm variable throughout the Demand class you’ll need to set it as a property of the class like so:

    class Demand()
    {
        /**
         * Declare the variable as a property of the class here
         */
        public $gcm;
    
        ...
        function __construct()
        {
            ...
            $this->gcm = new GCM();
            ...
        }
    
        function myFunction()
        {
            ...
            // You can access the GCM class now in any other method in Demand class like so:
            $result = $this->gcm->send_notification($registatoin_ids, $message);
            ...
        }
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GCM class, which gets a message that has 2 separate strings
I have Datastore Class and I use this class to try GCM . I
I was trying to use GCM to have push-notification in my app. I called
cannot use the GCMRegisterar from gcm.jar which i have added to build path ,but
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
I have migrated my app to use the new GCM push system. It works
I'm creating an app which uses Facebook and GCM. A user can use the
I have made an application which is using GCM push messaging framework for getting
I am trying to send a message through GCM (Google Cloud Messaging). I have

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.