ddubs Posted November 4, 2011 Share Posted November 4, 2011 So I'm pounding away at some of the new 5.3 features to try and get a grasp on setting up a custom MVC. spl_autoload with namespaces is frikkin awesome, however im trying to make life easy by being able to drop a class file in an "objects" folder that holds all the models for the app and have the controller parse out the get request for the proper model call and dynamically create the object. Example: url = www.example.com/?auth controller parses $_GET and see's you are requesting the auth module. Now I'm having an issue instantiating a variable that has a namespace\class inside it: $namespace = 'objects\\'; $clean['object'] = $namespace.key($clean['get']); $this->object = new $clean['object']; Logfile: PHP Fatal error: spl_autoload(): Class objects\\testobject could not be loaded... OK, its trying to escape the backslash? Maybe some trickery is needed? $clean['object'] = $namespace.chr(92).key($clean['get']); NOPE, still the same error... Any cluepons? Quote Link to comment https://forums.phpfreaks.com/topic/250450-dynamic-namespaced-class-instantiation/ Share on other sites More sharing options...
ddubs Posted November 4, 2011 Author Share Posted November 4, 2011 Finally googled the proper combo *sigh* I needed to: $object = "\\objects\\class" $works_now = new $object; hah... Quote Link to comment https://forums.phpfreaks.com/topic/250450-dynamic-namespaced-class-instantiation/#findComment-1285013 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.