Jump to content

Recommended Posts

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.  :confused: 

 

Thanks and rgds  8)

 

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.)

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.