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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:19:58+00:00 2026-06-14T09:19:58+00:00

Is it possible to instantiate multiple times the same class in a simplified way

  • 0

Is it possible to instantiate multiple times the same class in a simplified way other than this I have?

include ("php/functions.php");

date_default_timezone_set('Europe/Lisbon');

require 'php/gapi.class.php';
$ga1 = new gapi('XXXX@gmail.com','XXXX');
$ga2 = new gapi('XXXX@gmail.com','XXXX');
$ga3 = new gapi('XXXX@gmail.com','XXXX');

$ga1->requestReportData( $report_id = XXXX, $dimension = array('browser'), $metrics = array('visitors','pageviews','visits'), $sort_metric = '-visitors', $filter = 'browser == Firefox || browser == Chrome || browser == Internet Explorer || browser == Safari || browser == Opera && visits > 10', $start_date = '2012-10-17' );

$ga2->requestReportData( $report_id = XXXX, $dimension = array('country'), $metrics = array('visitors','pageviews','visits'), $sort_metric = '-visits', $filter = 'country != (not set) && visits > 3', $start_date = '2012-10-17', null, null, 10 );

$date2 = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")-15, date("Y")));
$today = date('Y-m-d');
$ga3->requestReportData($report_id = XXXX, $dimension = array('date'), $metrics = array('pageviews','visits'), $sort_metric = array('date')  , $filter = '',$date2,$today, null,15);

PS: This code works as intended … I was just wondering if there’s a more efficient way to achieve this…

EDIT: To answer some questions made on some of the solutions provided, here’s an example of application a couple hundred lines later on the same file:

      <h2 class="verde">By country (10 relvant results)</h2>
      [useless code ommited...]
      <tbody>
        <?php
        $tp = 0;
        foreach($ga2->getResults() as $r2){
          if($tp==10) break;
        ?>
        <tr>
          <td><?php echo $r2 ?></td>
          <td><?php echo $r2->getVisitors() ?></td>
          <td><?php echo $r2->getVisits() ?></td>
          <td><?php echo $r2->getPageviews() ?></td>
        </tr>
        <?php
        $tp++;
        }
        ?>
        <tr style="font-weight:700">
          <td><strong>TOTAIS</strong></td>
          <td><strong><?php echo $ga2->getVisitors() ?></strong></td>
          <td><strong><?php echo $ga2->getVisits() ?></strong></td>
          <td><strong><?php echo $ga2->getPageviews() ?></strong></td>
        </tr>
      </tbody>

I’m not sure if I can post links here … but this code can be seen on http://jb.utad.pt/gapi/

  • 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-14T09:19:59+00:00Added an answer on June 14, 2026 at 9:19 am

    You just need one object to access a function. You may change the parameters passed to the function according to your needs.

    Having multiple objects of the same class, is not efficient code, as each object takes up that much extra memory.

    Hence, you just need,

     $ga = new gapi('XXXX@gmail.com','XXXX');
     $ga->requestReportData( $report_id = XXXX, $dimension = array('browser'), $metrics =   array('visitors','pageviews','visits'), $sort_metric = '-visitors', $filter = 'browser == Firefox || browser == Chrome || browser == Internet Explorer || browser == Safari || browser == Opera && visits > 10', $start_date = '2012-10-17' );
     $ga->requestReportData( $report_id = XXXX, $dimension = array('country'), $metrics = array('visitors','pageviews','visits'), $sort_metric = '-visits', $filter = 'country != (not set) && visits > 3', $start_date = '2012-10-17', null, null, 10 );
     $date2 = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")-15, date("Y")));
     $today = date('Y-m-d');
     $ga->requestReportData($report_id = XXXX, $dimension = array('date'), $metrics = array('pageviews','visits'), $sort_metric = array('date')  , $filter = '',$date2,$today, null,15);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is this possible? What I want to do is have my doWork method instantiate
Possible Duplicate: Storyboard Could not instantiate class named UIStoryboardUnwindSegueTemplate crash As with this question
Possible Duplicate: Instantiate a class with or without parentheses? This is a minor quibble,
Hi i have this class to instantiate DAL classes: public class Factory { public
Say you have two classes, A and B. Is it possible to instantiate both
Is it possible in PHP to instantiate an object from the name of a
Is it possible to assure that only spring can instantiate a class, and not
I have multiple processes in my linux environment that have to use the same
Is it possible to instantiate a Controller class within another controller class using the
Possible Duplicate: using a template class without a template argument If I have a

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.