Jump to content

[SOLVED] classes


popcornplya

Recommended Posts

Then its not extending the classes, its just simply used within them. eg;

 

<?php

class foo {

  private $db;

  function __construct() {
    require_once 'yourdbclass.class.php';
    $this->db = new yourdbclass;
  }

  function usedbclass() {
    $sql = "SELECT * FROM tbl";
    return $this->db->query($sql);
  }

}

?>

Link to comment
https://forums.phpfreaks.com/topic/149173-solved-classes/#findComment-783458
Share on other sites

well, what do you mean by wanting it to "work?"

 

You are asking for the best way for one class to "inherit" another class.  You need to be a lot more specific with your scenario than how you're being now, if you want any meaningful answers.  Depending on what you are wanting to do, you may just need to instantiate an object of your database class, and use that in your new class.  Or your situation may call for extending the database class.  Or you may end up needing to bust out with an interface.  Who knows? Without details, we cannot give you any good advice.

Link to comment
https://forums.phpfreaks.com/topic/149173-solved-classes/#findComment-783460
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.