Quantcast
Channel: When to use a Class vs. Function in PHP - Stack Overflow
Viewing all articles
Browse latest Browse all 7

Answer by Kaleb Brasee for When to use a Class vs. Function in PHP

$
0
0

Classes are used for representing data as objects. If you're representing something like a user's data, or an auction bid, creating a User object or AuctionBid object makes it easier to keep that data together, pass it around in your code, and make it more easily understandable to readers. These classes would have attributes (data fields like numbers, strings, or other objects) as well as methods (functions that you can operate on any class).

Classes don't usually offer any benefits in terms of performance, but they very rarely have any negative effects either. Their real benefit is in making the code clearer.

I recommend you read the PHP5 Object-Oriented Programming guide and the Wikipedia OOP entry.


Viewing all articles
Browse latest Browse all 7

Latest Images

Trending Articles





Latest Images