Go Back   CodeCall Programming Forum > Web Development Forum > PHP Forum
Register Blogs Search Today's Posts Mark Forums Read

PHP Forum Use this forum to discuss all aspects of PHP Development. PHP is a server-side, cross-platform, HTML embedded scripting language that lets you create dynamic web pages.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-20-2009, 11:16 AM
Jacki's Avatar
Learning Programmer
 
Join Date: Sep 2009
Location: Switzerland
Age: 16
Posts: 79
Jacki is on a distinguished road
[PHP] Intialized class and not-initialized class, differences?I

hi people,
I have a simple question. I have two ways to use a class in php:
PHP Code:
//initializing object
$myclass = new myClass;
// or not initializing class..

$myclass->myfunction();
myClass::myfunction(); 
What are the differences? When I have to use one and when i have to use the other? Thanks... bye!
__________________


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-20-2009, 11:49 AM
Orjan's Avatar
Moderator
 
Join Date: Sep 2007
Location: Karlstad, Sweden
Age: 34
Posts: 2,553
Orjan is a glorious beacon of lightOrjan is a glorious beacon of lightOrjan is a glorious beacon of lightOrjan is a glorious beacon of lightOrjan is a glorious beacon of light
Send a message via MSN to Orjan Send a message via Skype™ to Orjan
Re: [PHP] Intialized class and not-initialized class, differences?I

if you instansiate an object from the class, as you do in your first example, it will be initialized as well, having it's constructor done, creating an object of it's members and methods. with this object, you can perform different things as in your second codeline.

second line of yours will only work on instansiated objects, and that normally performs an action on that object, or retirns info from the object.

third line is what most call a static call to a method, usually a method that does not rely on anything else in the class, that just performs a calculation or what it is meant to do.
__________________
Ask me: Orjan | Contribute to the Wiki! | Make your own Programming blog!
I usually play eRepublik and Travian when I'm not on CodeCall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes



All times are GMT -5. The time now is 10:34 AM.


vBulletin v3.8.0 ©2010, Jelsoft Enterprises Ltd.


no new posts

LinkBacks Enabled by vBSEO 3.1.0