Jump to content

Recommended Posts

I *think* this has something to do with the way I've started using classes.

 

I used to do this:

 

$class = classname();

$class->classfunction();

 

but now I simply do this:

 

classname::classfunction

 

Yet now when I use $this within 'classname' it says:

 

"Using $this when not in object context"

 

If that is the problem, is there any other way to use 'this' with this method or will I have to create the object first?

 

Appreciate any help.

Link to comment
https://forums.phpfreaks.com/topic/188775-using-this-but-not-working/
Share on other sites

..thanks! I tend to use classname::classfunction(); quite a lot now when outside classes instead of creating an object at the top of my scripts.

 

Does this have any performance impact?

 

classname::classfunction1();

.....

classname::classfunction2();

 

OR

 

$classname = classname();

$classname->classfunction1();

....

$classname->classfunction2();

 

Thanks again, appreciate the help.

Thanks Daniel! ..and good point. I don't think I've come up against anything which requires me to use classes in such a way and I must admit, I am a bit out of my depth when it comes to OOP. I guess I use classes to arrange my functions then :D

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.