A function is a piece of code that is called by name. It can be passed data to operate on (i.e. the parameters) and can optionally return data (the return value). All data that is passed to a function is explicitly passed.
A method is a piece of code that is called by a name that is associated with an object. In most respects it is identical to a function except for two key differences:
- A method is implicitly passed the object on which it was called.
- A method is able to operate on data that is contained within the class (remembering that an object is an instance of a class – the class is the definition, the object is an instance of that data).
(this is a simplified explanation, ignoring issues of scope etc.)
Related Posts:
- “Parameter” vs “Argument”
- Inheritance vs. Aggregation [closed]
- What is dependency injection?
- What does ‘super’ do in Python? – difference between super().__init__() and explicit superclass __init__()
- What is Inversion of Control?
- What is ADT? (Abstract Data Type)
- What is an example of the Liskov Substitution Principle?
- What __init__ and self do in Python?
- When should you use a class vs a struct in C++?
- C++ error ‘Undefined reference to Class::Function()’ [duplicate]
- How do I implement interfaces in python?
- What is polymorphism, what is it for, and how is it used?
- java – invalid method declaration; return type required [duplicate]
- java – invalid method declaration; return type required
- Is C++ an Object Oriented language?
- Difference between abstraction and encapsulation?
- What are metaclasses in Python?
- What is the difference between a framework and a library?
- extends class and implements interface in java
- What is a “driver class”?
- What is difference between functional and imperative programming languages?
- How can I create a copy of an object in Python?
- Prefer composition over inheritance?
- What is polymorphism in Javascript?
- When should I be using classes in Python?
- includes() not working in all browsers
- How to return a boolean method in java?
- How to create a subclass in C#?
- How would one write object-oriented code in C?
- How to get a JavaScript object’s class?
- What is a coroutine?
- Parameter name omitted error?
- What is the difference between an Instance and an Object?
- What does ‘low in coupling and high in cohesion’ mean
- What is an example of the Single Responsibility Principle?
- Will WordPress become completely OOP?
- How to name files of namespaced classes?
- What is the best way to instantiate a class of a plugin in your WordPress theme?
- problem with implementing widget via the_content()
- Load classes using spl_autoload_register
- UML diagrams of WordPress
- Trying to get property of non-object
- Static vs Dynamic methods in WordPress
- Autoloader not finding classes from my plugin
- Integration tests test script enqueue/register fails
- Error of “Call a member function on non object” while var_dump get correct result
- How pass args to wp_list_comments callback?
- Does &$this is really disallowed to use anywhere?
- Don’t filters violate the a class’ local variables visibility rules?
- Admin submenu does not call function to load the page
- Using Geo Data Store Plugin Code
- How to wait for WordPress Core to load when writing OOP?
- OOP – from plugin add new object and call static method in another file
- How to get parameters with add_filter with a static method?
- What is tail recursion?
- Understanding Python super() with __init__() methods [duplicate]
- What is a loop invariant?
- Define a global variable in a JavaScript function
- What is the difference between tree depth and height?
- What is the difference between concurrency and parallelism?
- Difference between virtual and abstract methods
- Does Java support default parameter values?
- C++ BlackJack Stuck trying to program Ace
- What are sessions? How do they work?
- What is spaghetti code?
- HTTP Status 405 – Request method ‘POST’ not supported (Spring MVC)
- what does “nulled script” mean?
- Pass Method as Parameter using C#
- What does ‘public static void’ mean in Java?
- Can you write nested functions in JavaScript?
- Verify a method call using Moq
- What’s wrong with overridable method calls in constructors?
- “public” or “private” attribute in Python ? What is the best way?
- Converting EBNF to BNF
- What does the variable $this mean in PHP?
- How can you use php in a javascript function
- Why do some hooks not work inside class context?
- WP Plugin + OOP: Adding Menu Page doesn’t create required effect
- WordPress Ajax callback function from plugin – OOP
- Override WP Class Private Function
- Applying OO patterns and principles to plugin development
- How to prevent XSS alter custom global javascript object & methods in WordPress
- Most efficient way to use classes to create admin pages using Settings API
- Basic Object Oriented plugin question
- How can I unhook this action that was added via $this?
- How to access OOP plugin function inside themes or other plugin
- How to call a function from a shortcode function in an oop plugin
- Use PHP Class in WordPress functions
- Woocommerce functions in custom class, avoid errors
- Proper use of Output Buffer for a whole php clas
- Calling WordPress hook from within a class: call to undefined function error
- Class called in template, AJAX not registering
- How is construct function working even when variable is assigned null value?
- Code works on a page but not in a widget
- What is wrong with assigning values to a WP_List_Table class?
- wpdb insert working in one function, but not another
- OOP – add_action
- Plugin won’t activate, fatal error (widget class not found)
- How do I create Widget within plugin that uses its own class?
- Keeping Objects in Memory