Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Scope Resolution Operator PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 185
    Comment on it

    In Programming language we use the scope resolution operation in different ways. Here we are taking about the its uses in PHP. PHP is easy to use and manage. Scope resolutionary operator is also known as double colon. This is basically a operator which can be useful to access the constants and static variables outside the class. I am going to take an small example to explain the same. Please have a look.

    class ScopeOperator
    {
        const myvar = "Welcome to Findnerd";
    }
    $con_outside =  ScopeOperator::myvar;

    In above example we build a class and intialize a constant with public visibility. We can use that constant outside the class by using class name and scope resolution operator. If you want to use the constant inside the class then you need to use the keyword self instead of class name. Please have a look.
     

    class Inside_operator
    {
        const myvar = "Welcome to Findnerd";
        function set_manager()
        {
           $inside_con = self::myvar;    
        }
    }

    In above example you used the self operator to get the constant value inside the function.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: