doukekui0914 2014-12-22 13:50
浏览 14

php - laravel - 不应该是抽象的

I'm trying to get a public version of my website going. I can connect to the page. routing is working.

The app is working with an API, and that is giving errors:

ErrorException in Transformer.php line 16:
Runtime Notice: Static function App\Transformers\Transformer::transform() should not be abstract

The transformer get's called like this: FeedTransformer::transformCollection( $userFeed ) and this is build up like following:

FeedTransformer.php

<?php
namespace App\Transformers;

use App\Story;
use App\Post;
use Illuminate\Database\Eloquent\Model;

class FeedTransformer extends Transformer {

  public static function transform(Model $item, $args = [ ]) {
    $return = array();

    if ($item instanceof Story) {
      $return = StoryTransformer::transform( $item, [ 'level' => 'story' ] );
    }
    if ($item instanceof Post) {
      $return = PostTransformer::transform( $item, [ 'level' => 'posts' ] );
    }

    return $return;
  }
}

and the Transformer.php

<?php
namespace App\Transformers;

use Illuminate\Database\Eloquent\Model;

abstract class Transformer {
  public static function transformCollection($items, $args = []) {
    foreach ($items as $item) {
      array_push( $var, static::transform( $item , $args) );
    }
    return $var;
  }

  public static abstract function transform(Model $item,$args = []);
}

So I'm not fully sure why this is causing an error on my server while not on my localhost development

Anyone got a clue why this error is being thrown?

  • 写回答

1条回答 默认 最新

  • duanjie5570 2014-12-22 14:02
    关注

    A static function can be called without creating an instance of the object, so declaring a static method as abstract is not supposed to happen.

    You can use Interfaces if you want to declare which methods a class has to implements.

    EDIT: otherwise, you have to declare your class without the Abstract word.

    评论

报告相同问题?

悬赏问题

  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真