П О Р Т А Л                            
С Е Т Е В Ы Х                          
П Р О Е К Т О В                        
  
                                                 
Главная

О проекте

Web-мастеру
     HTML & JavaScript
     SSI
     Perl
     PHP
     XML & XSLT
     Unix Shell

MySQL

Безопасность

Хостинг

Другое







Самое читаемое:

Учебник PHP - "Для Чайника".
Просмотров 98194 раз(а).

Иллюстрированный самоучитель по созданию сайтов.
Просмотров 29079 раз(а).

Учебник HTML.
Просмотров 56201 раз(а).

Руководство по PHP5.
Просмотров 25940 раз(а).

Хостинг через призму DNS.
Просмотров 30469 раз(а).

Подборка текстов стандартных документов.
Просмотров 28983 раз(а).

Учебник PHP - Самоучитель
Просмотров 33731 раз(а).

Документация на MySQL (учебник & справочное руководство)
Просмотров 34989 раз(а).

Внешние атаки...
Просмотров 26957 раз(а).

Учебник PHP.
Просмотров 22784 раз(а).

SSI в примерах.
Просмотров 17856 раз(а).



 
 



Руководство по PHP
Пред. Глава 19. Классы и объекты (PHP 5) След.

Static Keyword

Declaring class members or methods as static makes them accessible without needing an instantiation of the class. A member declared as static can not be accessed with an instantiated class object (though a static method can).

The static declaration must be after the visibility declaration. For compatibility with PHP 4, if no visibility declaration is used, then the member or method will be treated as if it was declared as public.

Because static methods are callable without an instance of the object created, the pseudo variable $this is not available inside the method declared as static.

In fact static method calls are resolved at compile time. When using an explicit class name the method is already identified completely and no inheritance rules apply. If the call is done by self then self is translated to the current class, that is the class the code belongs to. Here also no inheritance rules apply.

Static properties cannot be accessed through the object using the arrow operator ->.

Calling non-static methods statically generates an E_STRICT level warning.

Пример 19-14. Static member example

<?php
class Foo
{
    
public static $my_static = 'foo';

    
public function staticValue() {
        return
self::$my_static;
    }
}

class
Bar extends Foo
{
    
public function fooStatic() {
        return
parent::$my_static;
    }
}


print
Foo::$my_static . "\n";

$foo = new Foo();
print
$foo->staticValue() . "\n";
print
$foo->my_static . "\n";      // Undefined "Property" my_static

// $foo::my_static is not possible

print Bar::$my_static . "\n";
$bar = new Bar();
print
$bar->fooStatic() . "\n";
?>

Пример 19-15. Static method example

<?php
class Foo {
    
public static function aStaticMethod() {
        
// ...
    
}
}

Foo::aStaticMethod();
?>

Пред. Начало След.
:: Уровень выше Константы в объектах


 





Copyright © 2005-2011 Project.Net.Ru