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,