pTutorial

New way to learn PHP

PHP 5 Scope resolution operator (::)

Scope resolution operator

Scope Resolution Operator is used in many ways in PHP 4 classes all are listed following below

  • It is used to access the parent class properties or methods of the class.
  • It is used to call the static properties of a class.
  • It is used to access to class constants.

Example

<?php

Class Book
{
Const NAME = " Let us C";
Const AUTHOR="Yashwant Kanetkar";
}

echo "Name of Book:
"; echo Book::NAME; echo "
Name of Author:
"; echo Book::AUTHOR; ?>

Output

Name of Book:
Let us C
Name of Author:
Yashwant Kanetkar

In the class Book NAME and AUTHOR are class constant and accessing by the Scope resolution operator, as shown above.

Download


Static property by Scope resolution operator

<?php

class Computer
{
	static $name="Dell";
    static function display()
	{
	echo Computer::$name;
	}
}

echo Computer::$name;
echo Computer::display();

?>

Output

Dell
Dell


QUOTES OF THE DAY

A good beginning makes a good ending.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER