Jump to content

Search the Community

Showing results for tags 'class circular global'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. I have a core class that does the majority of the heavy lifting for my framework. I also use an external class "access" to check for user access to resources. While trying to streamline things a bit I noticed that when I create an "access" object outside of my "core" class that I have to declare my "access" object as global anytime I want to use it inside the "core" class. Example: class core() { public somefunction() { global $Access; //... Etc ... } } $Access = new access(); $Core = new core(); $Core->somefunction(); I want to do: class core() { public somefunction() { // $this->Access now available here w/o declare global //... Etc ... } public initAccess() { $this->Access = new access(); //... Etc ... } } The Problem is that "access" class uses the DB connection and query function inside "core". I am worried about circular references. Any gurus have advice on such an issue or am I worried about nothing? Here is a snippet of the actual code pared down to minimum: <?php class myCore { private $_Ini=array(); // Main Ini Info Array public $_DB=''; // DB Connection private $_ACCESS=false; // Hold Access Class Instance public function __construct() { $this->_Ini = parse_ini_file(ABSPATH.DS."config.php", true); $this->connect(); $this->initAccess(); }// End Constuct public function connect() { if(!defined(HOST)) { $dbauth = $this->_Ini['database']; define ('HOST',$dbauth['HOST']); define ('DB_USER',$dbauth['DB_USER']); define ('DBPASS',$dbauth['DBPASS']); define ('DB',$dbauth['DB']); } $this->_DB = @new mysqli(HOST, DB_USER, DBPASS,DB); /* check connection */ if ($this->_DB->connect_error) trigger_error('Database connection failed in '.__FILE__.' at '.__LINE__.':'.$this->_DB->connect_error, E_USER_ERROR); } //end connect // Central Query Function public function DBquery($query,$Location) { $result = $this->_DB->query($query) or trigger_error('<strong>Query Error:</strong> '.$this->_DB->error. '<br/><strong>Query Location:</strong> '.$Location. '<br/><strong>Query:</strong> '.$query, E_USER_ERROR); return $result; }// End DBquery() // Initiate Access class public function initAccess() { $this->_ACCESS = new Access($_SESSION['UsrNum'],$this); }// End initAccess() /* * Bunch of other Functions... */ } class Access { /** * Checks user access for resources */ private $user; private $_CORE; public function __construct($user,&$CORE_Class) { $this->_CORE = $CORE_Class; $this->user = $user; } // End __construct public function getRole() { $result = $this->_CORE->DBquery('SELECT `group` FROM `user_role` WHERE `user`='.$this->user,__FILE__.' at '.__LINE__); while($row=$result->fetch_array(MYSQLI_ASSOC)) $role[]= $row['group']; return $role; } // End getRole /* * Bunch of other Functions... */ } $MYcore = new myCore(); $MYcore->_ACCESS->getRole(); ?>
×
×
  • 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.