Jump to content
  • 0

азы 2


dostel1
 Share

Question


class A
{
function foo()
{
if (isset($this)) {
echo '$this определена (';
echo get_class($this);
echo ")\n";
} else {
echo "\$this не определена.\n";
}
}
}

class B
{
function bar()
{
// Замечание: следующая строка вызовет предупреждение, если включен параметр E_STRICT.
A::foo();
}
}

$a = new A();
$a->foo();

Что делают "::"?Как забить в поиске гугле что это?

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Что делают "::"?Как забить в поиске гугле что это?

забить "обращение к методу класса php"

цитирую первую ссылку:

Используя оператор :: можно обращаться к константам, статическим или перегруженным свойствам или методам класса.

свойства - переменные, методы - функции внутри класса.

Используя :: можно обращаться напрямую к свойствам или методам указанного класса (причем без инициализации самого класса)

class A {
static $bar = 'bar';
function foo() {
echo 'foo';
}
}
A::foo();
echo A::$bar;

P.S. изучать ООП лучше всего на практике, а лучшая практика с ООП - фреймворки с низким входным порогом (Yii, CodeIgniter)

Edited by NeoXidizer
  • Like 1
Link to comment
Share on other sites

  • 0

dostel1, у тебя пример очень древний, для PHP 5x (а он практически везде сейчас) нужно писать

public static function foo(){...}

это ошибкой не является, все методы по умолчанию создаются в зоне видимости public

Class methods may be defined as public, private, or protected. Methods declared without any explicit visibility keyword are defined as public.
For compatibility with PHP 4, if no visibility declaration is used, then the property or method will be treated as if it was declared as public.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy