关键词抽象在界面中的意义是什么?我试图在界面中写抽象关键字。
<?php
interface I
{
abstract function test ();
}
class A implements I{
public function test ($offset)
{
}
}
$x=new A();
?>
获取错误:
Fatal error: Access type for interface method I::test() must be omitted in test.php on line 4
但是这里所有的方法都是抽象的,
我只是写了这样的代码:
<?php
class test
{
// Force Extending class to define this method
abstract protected function getValue();
abstract protected function prefixValue($prefix);
// Common method
public function printOut() {
print $this->getValue() . "\n";
}
}
class testabs extends test{
pu
为什么我不能在接口中声明抽象方法?这是我的代码。谢谢。
<?php
interface Connection {
public abstract function connect();
public function getConnection();
}
abstract class ConnectionAbstract implements Connection() {
private $connection;
public abstract function connect();
public function getConnection
<?php
abstract class file
{
private $pid;
private $uid;
public function __construct($pid,$uid)
{
$this->pid = $pid;
$this->uid = $uid;
}
public function valid()
{
if($_SESSION['level']<$this->pid)
{
ret
我偶然发现了一些由同事编写的PHP代码(它没有任何用途)。基本上,它是一个包含抽象方法的接口。然后我说这很愚蠢,并展示了另一位同事坐在我旁边。我们笑了,然后开始问对方这是否可能,如果是的话,它是否真的有用。显然这是不可能的(见下面的例子),但如果它是可能的,它是否有用。
你能想到这可能有用的情况吗?
<?php
interface Itest
{
abstract public function add(int $x, int $y);
}
abstract class ParentTest implements Itest
{
我想很多人都会怀疑这是否可能,但我找不到任何重复的问题……一定要纠正我。
我只想知道PHP是否提供纯虚函数。我想要以下内容
class Parent {
// no implementation given
public function foo() {
// nothing
}
}
class Child extends Parent {
public function foo() {
// implementation of foo goes here
}
}
非常感谢。
我使用Intellij开发php。
class A {
}
class B extends A {
public function myFunc() {}
}
class C {
/**
* Return class object
*
* @return A
*/
public function get() {
return $a_or_child_a_class_from_some_list;
}
}
$cObject = new C();
$cObject
->get()
->myFunc()
我正在努力让我的网站有一个公开的版本。我可以连接到该页面。路由工作正常。
这个应用程序正在使用一个API,这会给出错误:
ErrorException in Transformer.php line 16:
Runtime Notice: Static function App\Transformers\Transformer::transform() should not be abstract
转换器get是这样调用的:FeedTransformer::transformCollection( $userFeed ),它是这样构建的:
FeedTransformer.php
<?ph
我对抽象类有点困惑了!我已经读了更多的文章写的堆叠溢出和另一个网站,但我不明白!所以我又看了看我的书,但我也不明白。因此,请逐步分析下面的代码:
提前感谢
<?php
abstract class AbstractClass
{
abstract protected function getValue();
public function printOut() {
print $this->getValue();
}
}
class ConcreteClass1 extends AbstractClass
{
protected function getValue() {
对于debug.log中的PHP严格标准,我有一个奇怪的警告。
PHP Strict standards: Declaration of gb_EntryList::fields() should be compatible with mgr_LinearModelCollection::fields($mKey = NULL) in ... on line 339
到目前为止,情况很糟,但是第339行保留了gb_EntryList类的定义。
class gb_EntryList extends mgr_mySQLModel
gb_EntryList根本没有定义fields()。它是从mgr
我正在用ajax编写PHP表单,但是初始化类ou类时遇到了问题。我认为问题在于路径,我有一个addproduct.php和这个表单,我不相信张贴表单会有帮助,因为它没有任何错误,但如果你认为是,让我知道,以便我可以张贴它。
这是我提交表单(posproduct.js)的地方。
$(document).on('submit', '#product_form', function(){
var $form = $('#product_form');
var dados = $form.serialize();
我在这里创建了一个包含抽象方法的类,它总是向我返回这个错误,即使该方法被声明为抽象的。下面是我的全部代码
<?php
interface Validator{
public function isValid($input);
public function getErrors();
}
class Validator_AbstractValidator
{
protected $_errors = array();
abstract public function isValid($input);
public function getErr
Heloo,我有以下错误:
致命错误:类CI_Session_files_driver包含两个抽象方法,因此必须在第49行的D:\wamp64\www\has\system\libraries\Session\drivers\Session_files_driver.php中声明抽象或实现其余方法(SessionHandlerInterface::open,SessionHandlerInterface::read)
我已经尝试从论坛提出解决方案,我已经取代了CI 3的系统文件夹,但仍然没有运气。重新启动apache可以临时修复问题。但过了一段时间,它还是回来了。这是我的工作环境:
W
我想做这样的事情:
abstract class Foo
{
public function __construct()
{
echo 'This is the parent constructor';
}
abstract function __construct();
}
class Bar extends Foo
{
// constructor is required as this class extends Foo
public function __construct()
{
我正在开发下一个版本的语言约束协调系统。我从这里开始( abstract函数声明似乎是问题所在):
namespace AAABIT;
abstract class LangPrefSet{
private $LangPrefs;
public function __construct(){$this->LangPrefs=array();}
public function add(LangPref $langpref){$this->LangPrefs[]=$langpref;}
public function langPrefs(){return
我一直在开发你的应用程序。我想知道是否有可能在模型行为中声明某种“抽象”方法。我知道,不可能直接使用以下声明:
abstract class FantasticBehavior extends CActiveRecordBehavior
{
public abstract function doSomethingFantastic();
}
因为我们需要这个类的一个实例。但我也知道Yii是充满魔力的:)
我只想让owner类按强制顺序从行为中重新声明方法。当然,除了行为之外,我还可以使用界面,但是.
对不起,如果我漏掉了什么要说的话或有什么不清楚的地方。只要问一问,我就试着解释我的意思
致命错误:类验证包含一个抽象方法,因此必须在第21行的C:\wamp\www\jump\task3\day8\abstract.php中声明抽象或实现其余方法(BaseValidator::SetRange)
<?php
abstract class BaseValidator
{
abstract function Validate($string);
abstract function SetRange($string);
}
class Validate extends BaseValidator
{
我当时正在开发一个PHP web应用程序。我使用了来自gurrido.net的一个新数据集,它在本地运行良好,但是当我将它上传到服务器时,我得到以下错误:
致命错误:无法使非静态方法Base::getClassName()在/var/www/reskb/phpinc/Singletons.class.php中的类中静态
在我不使用网格的旧版本中,我让它正常工作。下面是我的singletons.class.php文件代码:
<?
class Singletons extends Base {
var $objects = array();
function getC
我有一个类似于的类。我也会把它贴在下面供参考:
<?php
trait T1
{
abstract protected function _doStuff();
}
trait T2
{
protected function _doStuff()
{
echo "Doing stuff in trait\n";
}
}
class C
{
use T1 {
_doStuff as _traitDoStuff;
}
use T2 {
_doStuff as _tr
我的代码有什么问题吗?还是我真的不能在抽象类中实现接口?我的代码不工作,PHP抛出一个错误:
致命错误:找不到类“Blah”
我的代码:
interface IBlah {
public function Fun();
}
abstract class Blah implements IBlah {
public function FunCommon() {
/* CODE */
}
abstract public function Fun();
}
class Koko extends Blah {
public function Fun() {
我需要强制类实现一些方法,例如onCreate(),因为在php等其他语言中,我们可以看到类似这样的内容:
<?php
// Declare the interface 'Movement'
interface MovementEvents
{
public function onWalk($distance);
}
// Declare the abstract class 'Animal'
abstract class Animal implements MovementEvents{
protected $energy = 10
我只想要declare函数,,没有的实现。实现必须在另一个文件中。
这有可能吗?如果是的话,其中是否有一些棘手之处?这样做是否普遍的做法?我很好奇,因为我来自C++。
示例:
<?php
function first($name, $age);
function second($country);
?>
<?php
include (declarations.php);
function first($name, $age)
{
// here is the implementation
}
function second($country)
{
// he
我正在尝试学习PHP中的面向对象编程,现在我已经达到了抽象类。
我在理解何时应该在抽象类中实现抽象方法以及何时不应该实现抽象方法时遇到了一些问题。
例如,使用以下代码:
<?php
abstract class concept_car {
/**
* Properties can not be declared as abstract natively:
* http://stackoverflow.com/questions/7634970/php-abstract-properties
*/
protected $weelNum =
abstract class A {
abstract void area();
}
class B extends A {
void area(){
System.out.print("area by class B");
}
}
问题:-
这里,类A是一个抽象类,包含一个抽象方法area()。然后,类B extends抽象类A,并重写抽象方法area()。我在一本书中读到,如果一个类甚至包含一个抽象方法,那么整个类就变成抽象类。所以,我的问题是B类变得抽象与否?