Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2008
    Location
    Jupiter
    Posts
    49
    Thanks
    8
    Thanked 0 Times in 0 Posts

    What exactly is a property value

    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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    That would be you're object members. OOP in PHP is considered a more intermediate to advanced language handling.
    PHP Code:
    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.

    Edit:
    BTW, there is also static variables which are not quite local and not quite global.
    PHP Code:
    function myCount()
    {
        static 
    $i 0;
        return 
    $i++;
    }
    myCount();
    myCount();
    print 
    myCount(); // Returns 2 
    Last edited by Fou-Lu; 05-01-2009 at 12:56 AM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    tokio (05-01-2009)

  • #3
    New Coder
    Join Date
    Jun 2008
    Location
    Jupiter
    Posts
    49
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    That would be you're object members. OOP in PHP is considered a more intermediate to advanced language handling.
    PHP Code:
    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.

    Edit:
    BTW, there is also static variables which are not quite local and not quite global.
    PHP Code:
    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.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Thats correct. And it is local, so the same variable can be used in different classes.
    PHP Code:
    class MyClass
    {
        public 
    $variable;
    }

    class 
    MySecondClass
    {
        public 
    $variable;

    The $variable from MyClass holds no relationship to the $variable from MySecondClass.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    tokio (05-01-2009)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •