0

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?

Kiwi
  • 2,713
  • 7
  • 44
  • 82

1 Answers1

0

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.

Asenar
  • 6,732
  • 3
  • 36
  • 49
  • It's not for declaring what methods they should have, it's for having a method availible in all it's subclasses without having to recode it everytime. it works on my local dev version. – Kiwi Dec 22 '14 at 15:16
  • so you simply should remove the `Abstract` keyword in front of your class declaration, and move all the abstract things into an interface (for – Asenar Dec 22 '14 at 18:45