...

View Full Version : What exactly is a property value



tokio
05-01-2009, 12:51 AM
Im a beginning of php and im trying to master the basics. I understand that there are three variables, global, local, and property. However, i have no idea when the property variable is, or when it is used. Any links would be appreciated.

Tokio

Fou-Lu
05-01-2009, 12:54 AM
That would be you're object members. OOP in PHP is considered a more intermediate to advanced language handling.


class MyClass
{
private $property; //<-- Thats you're property right there
}


Properties are scoped by default to public (if PHP4 var is used) which allows access via object to any scope that the object resides in. Properties are local to an object.


BTW, there is also static variables which are not quite local and not quite global.


function myCount()
{
static $i = 0;
return $i++;
}
myCount();
myCount();
print myCount(); // Returns 2

tokio
05-01-2009, 02:00 AM
That would be you're object members. OOP in PHP is considered a more intermediate to advanced language handling.


class MyClass
{
private $property; //<-- Thats you're property right there
}


Properties are scoped by default to public (if PHP4 var is used) which allows access via object to any scope that the object resides in. Properties are local to an object.


BTW, there is also static variables which are not quite local and not quite global.


function myCount()
{
static $i = 0;
return $i++;
}
myCount();
myCount();
print myCount(); // Returns 2



So from your first example, it appears to be a variable that belongs to a specific class? Thanks.

Fou-Lu
05-01-2009, 03:16 AM
Thats correct. And it is local, so the same variable can be used in different classes.


class MyClass
{
public $variable;
}

class MySecondClass
{
public $variable;
}

The $variable from MyClass holds no relationship to the $variable from MySecondClass.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum