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

  • Home
  • SEARCH
  • 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 6117859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:22:08+00:00 2026-05-23T15:22:08+00:00

Using PHP5.3.3, I have 2 classes, called SinglePDO and Manager , both working, but

  • 0

Using PHP5.3.3, I have 2 classes, called SinglePDO and Manager, both working, but I’d certainly need your advices to optimize those unefficient code scriptings. Hence I have 2 questions but I guess strictly related one to another :


1) Access to the SinglePDO methods from a Manager object in the main code

From the main code :

$test=new Manager('mydbname', $some_parameters);
$dbfields = $test->getFieldsSummary(false);

In the Manager class, redefined function, provided it’s defined in the SinglePDO class :

public function getFieldsSummary($param)
{
    return $this->_dbh->getFieldsSummary($param);
}

Question:
How to get rid of the necessity to redefine all SinglePDO methods in the Manager class ?
(I have tried : class Manager extends SinglePDO and using : __call() but w/o success)


2) Split SinglePDO into 2 classes
The SinglePDO class embeds lots of methods. I’d like to unpack these methods and throw them into another class, say Tool overloading the SinglePDO class with method 1, method_2, etc…

Question :
How to achieve this in the previous context (still having the Manager Class)


Here is the SinglePDO class, a typical one but with additional methods.

       class SinglePDO extends PDO {
            private static $_dsn    = 'mysql:host=127.0.0.1;dbname=foobar';
            private static $_dbuser= 'dbuser' ;
            private static $_dbpwd  = 'dbpwd' ;
            private static $_lock = true;

        public function __construct( $dsn , $uname, $upass ) {

           if( self::$lock ) {
            trigger_error( 'Forbidden Class usage (singleton)');
           }
           parent::__construct( $dsn , $uname, $upass  );

        }

    public static function getInstance($dbh) {
        if( self::$instance == NULL ){
            self::$lock= FALSE;
                    self::$instance = new SinglePDO(self::$_dsn, self::$_dbuser, self::$_dbpwd);
                    self::$lock = TRUE;
        }
    return self::$instance;
    }

    /* lots of added methods that I'd like to drop into a Tool class  */
    public function my_method_1($param) {
     // do this and that
    }
} /* end of the uggly class */

EDIT:
In btwn, I found this very interesting link

  • 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-05-23T15:22:08+00:00Added an answer on May 23, 2026 at 3:22 pm

    For the first question, did you use call in conjunction with call_user_func_array? Because this has worked for me in projects before:

    function __call( $fname, array $fargs )
    {
        return call_user_func_array( array( $this->_dbh, $fname ), $fargs );
    }
    

    To question two: Well, if you get an answer to question 1 you will be able to get an answer to this as well. I might have something like:

    class PDOTool
    {
        /* why does getInstance have a parameter? */
        private static $pdo = SinglePDO::getInstance(NULL);
    
        public static my_method_1($param) {
           self::$pdo->doSomething($param);
        }
        /**  __callStatic works in PHP >= 5.3.0  */
        public function __callStatic( $fname, array $fargs )
        {
            return call_user_func_array( array( self::$pdo, $fname ), $fargs );
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using PHP5 to create XML files. I have code like this: $doc =
I'm building a web application using PHP5.3 and Zend Framework 1.9.4. i have an
How would one create a Singleton class using PHP5 classes?
I have a client using quickbooks on a Mac platform. I have a PHP5-based
I'm using PHP5 here. I have made a login system that check's the username
Greetings stackoverflow. I have been tinkering about with a SOAP client using PHP5's native
I'm using Tomcat and PHP5 with JavaBridge. I have bridged PHP and Java so
I'm new to php and I have created a simple site using php5. my
i am using php 5.2.8 i have index.html, which loads LOAD.PHP from IFRAME. iframe
I have HTML tidy extension on my home computer using PHP 5.2.11 (Windows -

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.