TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Another thought.. (http://www.talkphp.com/advanced-php-programming/3624-another-thought.html)

Tanax 11-17-2008 02:28 PM

Another thought..
 
Heya!

Here I am again, with one of those thoughts.. :-P

Basicly, is it possible to do this:
php Code:
<?php

    class core
    {
       
        private $class;
        public $settings = array();
       
        public function loadClass($name)
        {
           
            $class = new $name($this);
            return $class;
           
        }
       
       
    }
   
    class test
    {
       
        private $core;
       
        public function __construct($core)
        {
           
            $this->core = $core;
           
        }
       
        public function getSettings()
        {
           
            return $this->core->settings;
           
        }
       
    }
   
    $core = new core();
   
    $settings = array('website' => 'TalkPHP', 'username' => 'Tanax', 'email' => 'Tanax.ms@gmail.com');
    $core->settings = $settings;
   
    $test = $core->loadClass('test');
   
    var_dump($test->getSettings());


?>

Cause I need a baseclass(like a core) with all the settings. Then I have all kinds of other classes that I can load via the core. But I also need to be able to access properties and functions FROM the core INSIDE the other classes.

So can I do this?

And I know I can use extend to get similar functionality. But I'm wondering if THIS is possible.

Thanks in advance!

Tanax 11-17-2008 04:10 PM

Actually, nevermind. I tested this, and it worked :-D

Wildhoney 11-17-2008 06:40 PM

Hoorah for testing!

Tanax 11-17-2008 06:47 PM

Atleast I kept my code this time ;-) Haha


All times are GMT. The time now is 02:19 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0