silmeth
silmeth

Reputation: 700

What does assignment of literal to method/function mean in PHP?

I’m writing some code using PHP 5.5, and while writing I mistakenly wrote assignment instead of passing argument to methods, like below:

$user->setPostCnt = 0;
$user->setAdmin = false;

where it should be of course:

$user->setPostCnt(0);
$user->setAdmin(false);

And PHP, while parsing it, didn’t return any errors or warnings. Because of it I found problem (both parameters being null) much much later and I thought there is a bug in library I was using (ie. I was sure, while doing some data operations, library interprets both 0 and false as null).

So, what does this type of assignment:

$object->methodName = value;

mean in PHP?

Upvotes: 0

Views: 95

Answers (1)

Drixson Oseña
Drixson Oseña

Reputation: 3641

What do I understand that when you use

$object->methodName = value;

means you're accessing/assigning a property/variable of the class while

$user->setPostCnt(0); $user->setAdmin(false);

means you're acessing a method/function of the class

Upvotes: 1

Related Questions