0

First of all I thought python was madness but it looks like php is the wild west.

<?php
use Creations\Robot;

class RoboticAnimal extends Robot {
  use Creations\AnimalMixin;

  public function __construct ($speed, $name, $band, $wheels, $age, $weight, $blood_type) {
    parent::__construct($name, $band, $wheels);
    $this->__constructAnimal(now(), $age, $weight, $blood_type);
    $this->speed = $speed;
  }

  // !! Don't forget to override these on you object that extends RoboticAnimal !!
  // There should be a preprocces step to allow this:
  //   public static $foo = new AnimalTraits("Slug", 69, 420, 9001);
  public static $foo = [
     "AnimalType": "Slug",
     "MaxAmount": 69,
     "MatingSpeed": 420,
     "PowerLevel": 9001
  ];

  public static $robotTraits = [ "Immortal": true ]; 

  ...
}

All the animals need to have these 4 parameters AnimalType MaxAmount MatingSpeed PowerLevel. So to manage these 4 values we created an AnimalTraits object because OOP is good, however we cant assign these animal traits instance to our class as seen in the code snippit (and comments).

Is there away to assign an object instance of class to a static member field of a different class? (see comments of static member in code) It seems like this should be possible considering we assign the array, and thats the OOP Way

Nick Delben
  • 95
  • 3
  • 14
  • There's a lot of stuff here, but it seems like you're just asking how to initialize a static property to something that isn't a constant. Is that right? – Barmar Feb 01 '20 at 01:36
  • 1
    The first line: `use /Creations/Robot;` should throw a syntax error. The namespace delimiter in PHP is backslash: `use Creations\Robot;` (the first slash isn't necessary with `use` statements). The same goes for the `use` statement for the trait inside the class. – M. Eriksson Feb 01 '20 at 01:38
  • Your declaration of `$foo` is also broken, not proper syntax for an associative array. Do yourself a favour and get a decent IDE, your learning curve will be massively reduced. – YvesLeBorg Feb 01 '20 at 02:05

0 Answers0