criostage Posted August 6, 2013 Share Posted August 6, 2013 (edited) Hello, I would like to request a little of help in my code, I m trying to do an database for my movies in php, instead of using an framework or just do code without any structure, i decided to try adventure my self into higher grounds and try to make the application as a little framework that i could use for future projects the main reason behind this is mainly to learn proper PHP programing skills. In the past few weeks i have read online and changed my code so many times but or i m not understanding the class programing style or i m missing something. Here's my Work so far: Index.php <?php defined( 'DS' ) or define( 'DS', DIRECTORY_SEPARATOR ); defined( 'ABSPATH' ) or define( 'ABSPATH', dirname(__DIR__) ); defined( 'SYSPATH' ) or define( 'SYSPATH', ABSPATH . DS . 'System' ); defined( 'WEBPATH' ) or define( 'WEBPATH', ABSPATH . DS . 'Public' ); defined( 'PKGPATH' ) or define( 'PKGPATH', ABSPATH . DS . 'Packages' ); defined( 'APPPATH' ) or define( 'APPPATH', PKGPATH . DS . 'Application'); defined( 'COREPATH' ) or define( 'COREPATH', PKGPATH . DS . 'Framework' ); require ( PKGPATH . DS . 'Bootstrap.php'); Bootstrap.php <?php class Bootstrap{ static protected $_appConfig; static public function init ( ){ self::$_appConfig = APPPATH . DS . 'Config' . DS . 'Main.php'; require self::$_appConfig; var_dump($appOptions); } static private function setEnv( $appOptions ){ /** Set application enviroment to developer or 'production' */ Switch( is_bool( $appOptions['Developer'] ) ? $appOptions['Developer'] : FALSE ){ case TRUE: error_reporting( E_ALL ); ini_set( 'display_errors','On' ); break; default: error_reporting( E_ALL ); ini_set( 'display_errors', 'Off' ); ini_set( 'log_errors' ); ini_set( 'error_log', SYSPATH . DS . 'logs' . DS . 'errors.log' ); break; } /** Set's default timezone for this application */ date_default_timezone_set($appOptions['Timezone']); } } Bootstrap::init(); var_dump($appOptions); The Main.php file only contains the array appOptions (for now), i m thinking in the future adding the Database connection and Application requirements (example if you need mysql or gd modules installed). Okay now focusing on my question a little the output of the code above delivers the follow: array(2) { ["Developer"]=> bool(true) ["Timezone"]=> string(13) "Europe/Lisbon" } Notice: Undefined variable: appOptions in C:\EasyPHP\data\localweb\Framework\Packages\Bootstrap.php on line 33 NULL Note: 1st line is from the var_dump inside the init and 2nd is from outside the bootstrap class. With this i assume that the require i do in the init function only includes the file for the class and not for the application over all? is this the best way of doing an bootstrap or there's an better way? Thanks in advance, Edited August 6, 2013 by criostage Quote Link to comment https://forums.phpfreaks.com/topic/280880-requesting-a-little-help-in-my-bootstrap-code/ Share on other sites More sharing options...
boompa Posted August 6, 2013 Share Posted August 6, 2013 (edited) static public function init ( ){ self::$_appConfig = APPPATH . DS . 'Config' . DS . 'Main.php'; require self::$_appConfig; var_dump($appOptions); } Are you mixing and matching variable names in using appConfig and appOptions, or is appOptions somehow set elsewhere (like in the file required through $appConfig)? I see it dumped and used for operations, but I don't see it being set. If it is, then the scope of the included file would appear to be limited to the scope of the init() function. Edited August 6, 2013 by boompa Quote Link to comment https://forums.phpfreaks.com/topic/280880-requesting-a-little-help-in-my-bootstrap-code/#findComment-1443646 Share on other sites More sharing options...
criostage Posted August 6, 2013 Author Share Posted August 6, 2013 (edited) static public function init ( ){ self::$_appConfig = APPPATH . DS . 'Config' . DS . 'Main.php'; require self::$_appConfig; var_dump($appOptions); } Are you mixing and matching variable names in using appConfig and appOptions, or is appOptions somehow set elsewhere (like in the file required through $appConfig)? I see it dumped and used for operations, but I don't see it being set. If it is, then the scope of the included file would appear to be limited to the scope of the init() function. The $AppOptions is set in the Main.php File: <?php /** * Array that contains the application settings to be applied at it's startup. */ $appOptions = array ( 'Developer' => TRUE, 'Timezone' => 'Europe/Lisbon', ); The idea would be to apply this array to the bootstrap, in the furure i would like to add more options to that file Edited August 6, 2013 by criostage Quote Link to comment https://forums.phpfreaks.com/topic/280880-requesting-a-little-help-in-my-bootstrap-code/#findComment-1443647 Share on other sites More sharing options...
Solution trq Posted August 6, 2013 Solution Share Posted August 6, 2013 Functions, Methods and Classes all have their own scope. Variables that are defined within them, do not exist outside of them and vice versa. Quote Link to comment https://forums.phpfreaks.com/topic/280880-requesting-a-little-help-in-my-bootstrap-code/#findComment-1443652 Share on other sites More sharing options...
criostage Posted August 6, 2013 Author Share Posted August 6, 2013 Functions, Methods and Classes all have their own scope. Variables that are defined within them, do not exist outside of them and vice versa. So i guess i was right on my first bunches, tyvm for the information and sorry for the newbish question i was only used to do small scripts this will help me in the future. Quote Link to comment https://forums.phpfreaks.com/topic/280880-requesting-a-little-help-in-my-bootstrap-code/#findComment-1443673 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.