webref.eu Posted January 28, 2010 Share Posted January 28, 2010 Hi All I am trying unsuccessfully to set a variable within a class. The thing is, it appears to me that the class is getting instantiated by this line: require_once('class.shopcore.php'); and not using a "new" statement which is the only way I was familiar with to instantiate a class. Within the class.shopcore.php file is a class called shopcore, which I am guessing gets instantiated by default. Anyway, after the require_once line, I've added a call to a new function, SetKeyphrasePage, which I've created with the shopcore class, in order to set a KeyphrasePage variable within the shopcore class. So I have: require_once('class.shopcore.php'); $shopcore->SetKeyphrasePage( $KeyphrasePage ); This would be the common way of attempting to pass a value for a particular variable into a class. However, this isn't working, because it seems to be interfering with the whole shopcore class as I get a blank page. So, I guess my question is, does instatiating the class using require_once as per this example mean a different technique for setting a given variable in the class is needed? Thanks for any help ... I sure need it. Thanks and rgds Quote Link to comment https://forums.phpfreaks.com/topic/190136-question-on-require_once-and-class-variables/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 28, 2010 Share Posted January 28, 2010 The blank page is because you are getting a fatal runtime error because an instance of the calls does not exist and you are referencing it. You should be learning php, developing php code, and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that php would help you by displaying all the errors it detects (you can set these two values in your script, but parse errors won't be reported and displayed.) The require/include functions only read the contents of the file into the current script. If the file only contains a class definition, you still need to create an instance of that class before you can reference it (assuming you are not referencing static members of a class.) Quote Link to comment https://forums.phpfreaks.com/topic/190136-question-on-require_once-and-class-variables/#findComment-1003208 Share on other sites More sharing options...
webref.eu Posted January 28, 2010 Author Share Posted January 28, 2010 OK, thanks for that. What you're saying does seem to make sense. I think before I made alterations, the shopcore class was getting run by the require_once statement, but perhaps not properly instantiated as you have suggested. I will look into this more closely, thanks again. Rgds Quote Link to comment https://forums.phpfreaks.com/topic/190136-question-on-require_once-and-class-variables/#findComment-1003228 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.