php oo programming parent to instantiate child

Possible Duplicate: What exactly is late-static binding in PHP? I would like to build an abstract class that will instantiate it's child class using a static function. <?php class A { protected $value; public function __construct($value) { $this->value = $value; } public static function create($value) { /* A must not know about B!

PHP的oo编程父母来实例化孩子

可能重复: PHP中的后期静态绑定究竟是什么? 我想构建一个抽象类 ,它将使用静态函数实例化它的子类。 <?php class A { protected $value; public function __construct($value) { $this->value = $value; } public static function create($value) { /* A must not know about B! * I give that example for the context understanding */ return **n

Is instantiation required for function overriding?

Possible Duplicate: What exactly is late-static binding in PHP? In this example, PHP will print "NO" rather than "YES", opposite of what I expected. If I remove static on function c() , replace self:: with $this-> and do $e = new B; $e->c(); $e = new B; $e->c(); , things will work. Does this mean that instantiation is required to make functions in parent clas

函数重写需要实例吗?

可能重复: PHP中的后期静态绑定究竟是什么? 在这个例子中,PHP会打印出“NO”而不是“YES”,与我预期的相反。 如果我删除function c()中的static ,用self::替换self:: $this->然后执行$e = new B; $e->c(); $e = new B; $e->c(); ,事情会起作用。 这是否意味着实例化需要使父类中的函数调用继承类中的重载函数? (旁边的问题:这是一个PHP的怪癖,还是这个逻辑也适用于大多数其他编程语言?如果是这样,它

Calling a derived static method from a method in parent class in PHP

This question already has an answer here: What exactly are late static bindings in PHP? 7 answers You use late static binding for this Basically in the abstract class you call static::method() . This uses the method of the class that made the call. Abstract Class A{ public function foo(){ // Late static binding static::bar(); } abstract public static function

在PHP中用父类中的方法调用派生的静态方法

这个问题在这里已经有了答案: PHP中迟到的静态绑定究竟是什么? 7个答案 你使用迟的静态绑定 基本上在你调用static::method()的抽象类中。 这使用调用的类的方法。 Abstract Class A{ public function foo(){ // Late static binding static::bar(); } abstract public static function bar(); }

Difference between "include" and "require" in php

Is there any difference between them? Is using them a matter of preference? Does using one over the other produce any advantages? Which is better for security? You find the differences explained in the detailed PHP manual on the page of require : require is identical to include except upon failure it will also produce a fatal E_COMPILE_ERROR level error. In other words, it will halt the s

php中的“include”和“require”之间的区别

他们之间有什么区别吗? 正在使用他们的偏好问题? 使用其中一种产生任何优势吗? 哪种安全性更好? 您可以在require页面的详细PHP手册中找到不同之处。 require与include相同,除了在失败时它还会产生致命的E_COMPILE_ERROR级错误。 换句话说,它会停止脚本,而包含只发出警告( E_WARNING ),允许脚本继续。 请参阅@ efritz的答案为例 如果文件无法加载, require会抛出一个PHP致命错误。 (执行停止) 如果文

Include, require & require

Today I've tried to include file that returns object. I always use require_once, however now I've noticed weird behavior of it. File main.php $lang = false; $lang->name = "eng"; $lang->author = "Misiur"; $lang->text = "Text is test"; $lang->undefined = "Undefined"; return $lang; File index.php $lang = include('langs/eng/main.php'); var_dump($lang); echo "<br />"; $

包括,要求和要求

今天我试图包含返回对象的文件。 我总是使用require_once,但现在我注意到它的奇怪行为。 文件main.php $lang = false; $lang->name = "eng"; $lang->author = "Misiur"; $lang->text = "Text is test"; $lang->undefined = "Undefined"; return $lang; 文件index.php $lang = include('langs/eng/main.php'); var_dump($lang); echo "<br />"; $lang = require('langs/eng/main.php'); var_dump($lang);

PHP difference in accessing class methods

$foo->bar()和$foo::bar()什么区别? $foo::bar() is a call of the static method bar() , that means the object $foo was not instanciated by the __construct() method. When calling $foo->bar() , the object $foo has to be instanciated before! Example: $foo = new Foo; // internally the method __constuct() is called in the Foo class! echo $foo->bar(); Often you don't call a static met

访问类方法的PHP区别

$foo->bar()和$foo::bar()什么区别? $foo::bar()是静态方法bar()的调用,这意味着$foo对象不会被__construct()方法实例化。 当调用$foo->bar() , $foo对象必须先被实例化! 例: $foo = new Foo; // internally the method __constuct() is called in the Foo class! echo $foo->bar(); 通常情况下,您不会像现在的示例( $foo )那样在现有对象上调用静态方法,您可以直接在类Foo上调用它: Foo::bar();

PHP Using classes

Possible Duplicates: Reference - What does this symbol mean in PHP? PHP: Static and non Static functions and Objects In PHP, whats the difference between :: and -> ? I have seen different ways to use classes in PHP eg $myclass->method() or MyClass::method() what is the difference? From your example, $myclass appears to be an instance of the class MyClass and you are invoki

PHP使用类

可能重复: 参考 - 这个符号在PHP中的含义是什么? PHP:静态和非静态函数和对象 在PHP中,::和 - >有什么区别? 我已经看到了不同的方法来使用PHP中的类,例如 $myclass->method() 要么 MyClass::method() 有什么不同? 在你的例子中,$ myclass看起来是类MyClass的一个实例,并且你正在调用一个实例方法。 实例方法从类的实例中调用。 在第二个示例中,方法似乎是该类的静态方法。 在类级调用静态

Beginner help

Possible Duplicate: In PHP, whats the difference between :: and -> ? This a continuation from my previous question - however I think its unique enough to warrant a new question. What is the difference between: Message::listMessages(); and $message->listMessages(); I'm creating a mini-cms and I want a system that displays errors in a uniform fashion. Cheers, Keiran Static

初学者的帮助

可能重复: 在PHP中,::和 - >有什么区别? 这是我上一个问题的延续 - 但我认为它的独特性足以证明一个新问题。 有什么区别: Message::listMessages(); 和 $message->listMessages(); 我正在创建一个mini-cms,我想要一个以统一的方式显示错误的系统。 干杯,基兰 当我们想要在一个类的对象之间共享信息,或者想要表示与类本身相关的东西,而不是任何特定的对象时,静态方法就会派上用场。 两者的区别

>myMethod(); vs MyClass::myMethod();

Possible Duplicate: In PHP, whats the difference between :: (double colon) and -> (arrow)? I just had a quick question about what seems to me to be two different ways of doing the same thing. If there are difference other than syntax, please explain what they are. We'll assume we have a class called MyClass with a method called myMethod . What's in them probably isn't relev

> myMethod的(); vs MyClass :: myMethod();

可能重复: 在PHP中,::(双冒号)和 - >(箭头)有什么区别? 我只是对我看来是两种不同的方式来做同样的事情有个简单的问题。 如果语法不同,请解释它们是什么。 我们假设我们有一个名为MyClass的类,它有一个名为myMethod的方法。 它们中的内容可能不相关,因为我们只是从另一个文件中调用它们。 这是我知道的第一种方式(可能有其他方式 - 这些就是我所知道的): $myvar = new MyClass(); $myvar->myMethod

What is the difference between :: and

Possible Duplicates: Reference - What does this symbol mean in PHP? In PHP, whats the difference between :: and -> ? When you try to access property of method inside class whats the difference between :: and -> and is there full reference of operators related to object oriented programming in php somewhere? The :: is for static properties and methods, eg MyClass::create(); The -&

::和。之间的区别是什么?

可能重复: 参考 - 这个符号在PHP中的含义是什么? 在PHP中,::和 - >有什么区别? 当你尝试访问类中的方法的属性什么是::和 - >之间的区别,并有有关面向对象的编程在PHP某处的操作符的完整引用? ::是用于静态属性和方法的,例如 MyClass::create(); ->是用于从类中实例化对象的时候,例如 $myObject = new MyClass; $myObject->create(); 在使用::您可以静态访问一个Class方法,而无需创建该类的实