Jump to content

Using $this - but not working


Anti-Moronic

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.