method and function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ranjitbd
Forum Newbie
Posts: 24
Joined: Sun May 03, 2009 1:59 pm

method and function

Post by ranjitbd »

question 1.what is the difference between function and method in a php code...
question 2.
what is the difference between between two following declaration
$abc;
var $abc;
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: method and function

Post by requinix »

A function (or "subroutine") is a generic term. A method is a function that belongs to a class.
sprintf and mysqli_query are functions, DateTime::add and mysqli::query are methods.

$abc; is not a declaration. PHP does not have those for regular global variables.
var $abc; declares a member variable of a class. It is a PHP 4 feature (see this) and was replaced with public in PHP 5.
Post Reply