PHP 警告:class_parents():需要对象或字符串

PHP Warning: class_parents(): object or string expected

我正在使用 TYPO3,我的扩展中有我自己的模型、控制器和存储库文件。在后端,我创建了一个没有任何问题的记录。但是当我尝试加载 FE 时,我在 DataMapper.php

中收到以下错误
PHP Warning: class_parents(): object or string expected in /home/app/vendor/typo3/cms/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapper.php line 284

00284:  if ($propertyData['type'] === 'DateTime' || in_array('DateTime', class_parents($propertyData['type']))) {

我调试了它,发现 $属性Name 包含正确的 属性 名称 'street' 但 $属性Data 是一个空数组。

我的模型是这样的:

<?php

namespace Snowflake\Htwapartmentexchange\Domain\Model;

use Snowflake\ApiRepository\Helpers\DateTime;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;


class Apartment extends AbstractEntity
{
protected $apartmentType = '';
protected $street = '';
protected $zip = '';
protected $city = '';
protected $price = '';
protected $countRooms = '';
protected $area = '';
protected $availableDate = '';
protected $description = '';
protected $firstname = '';
protected $lastname = '';
protected $mobile = '';
protected $mail = '';
protected $pictures = null;

/**
 * Apartment constructor.
 * @param $apartmentType
 * @param $street
 * @param $zip
 * @param $city
 * @param $price
 * @param $countRooms
 * @param $area
 * @param $availableDate
 * @param $description
 * @param $firstname
 * @param $lastname
 * @param $mobile
 * @param $mail
 * @param $pictures
 */
public function __construct($apartmentType, $street, $zip, $city, $price, $countRooms, $area, $availableDate, $description, $firstname, $lastname, $mobile, $mail, $pictures)
{
    $this->apartmentType = $apartmentType;
    $this->street = $street;
    $this->zip = $zip;
    $this->city = $city;
    $this->price = $price;
    $this->countRooms = $countRooms;
    $this->area = $area;
    $this->availableDate = $availableDate;
    $this->description = $description;
    $this->firstname = $firstname;
    $this->lastname = $lastname;
    $this->mobile = $mobile;
    $this->mail = $mail;
    $this->pictures = $pictures;
}

/**
 * @return mixed
 */
public function getApartmentType()
{
    return $this->apartmentType;
}

/**
 * @param mixed $apartmentType
 */
public function setApartmentType($apartmentType)
{
    $this->apartmentType = $apartmentType;
}


/**
 * @return mixed
 */
public function getStreet()
{
    return $this->street;
}

/**
 * @param mixed $street
 */
public function setStreet($street)
{
    $this->street = $street;
}

/**
 * @return mixed
 */
public function getZip()
{
    return $this->zip;
}

/**
 * @param mixed $zip
 */
public function setZip($zip)
{
    $this->zip = $zip;
}

/**
 * @return mixed
 */
public function getCity()
{
    return $this->city;
}

/**
 * @param mixed $city
 */
public function setCity($city)
{
    $this->city = $city;
}

/**
 * @return mixed
 */
public function getPrice()
{
    return $this->price;
}

/**
 * @param mixed $price
 */
public function setPrice($price)
{
    $this->price = $price;
}

/**
 * @return mixed
 */
public function getCountRooms()
{
    return $this->countRooms;
}

/**
 * @param mixed $countRooms
 */
public function setCountRooms($countRooms)
{
    $this->countRooms = $countRooms;
}

/**
 * @return mixed
 */
public function getArea()
{
    return $this->area;
}

/**
 * @param mixed $area
 */
public function setArea($area)
{
    $this->area = $area;
}

/**
 * @return DateTime
 */
public function getAvailableDate()
{
    return $this->availableDate;
}

/**
 * @param DateTime $availableDate
 */
public function setAvailableDate($availableDate)
{
    $this->availableDate = $availableDate;
}


/**
 * @return mixed
 */
public function getDescription()
{
    return $this->description;
}

/**
 * @param mixed $description
 */
public function setDescription($description)
{
    $this->description = $description;
}

/**
 * @return mixed
 */
public function getFirstname()
{
    return $this->firstname;
}

/**
 * @param mixed $firstname
 */
public function setFirstname($firstname)
{
    $this->firstname = $firstname;
}

/**
 * @return mixed
 */
public function getLastname()
{
    return $this->lastname;
}

/**
 * @param mixed $lastname
 */
public function setLastname($lastname)
{
    $this->lastname = $lastname;
}

/**
 * @return mixed
 */
public function getMobile()
{
    return $this->mobile;
}

/**
 * @param mixed $mobile
 */
public function setMobile($mobile)
{
    $this->mobile = $mobile;
}

/**
 * @return mixed
 */
public function getMail()
{
    return $this->mail;
}

/**
 * @param mixed $mail
 */
public function setMail($mail)
{
    $this->mail = $mail;
}

/**
 * @return mixed
 */
public function getPictures()
{
    return $this->pictures;
}

/**
 * @param mixed $pictures
 */
public function setPictures($pictures)
{
    $this->pictures = $pictures;
}


}

你能告诉我哪里出了问题吗?

class_parents(new $propertyData['type']))) 

你应该为对象使用 new 关键字

第 284 行...

找到解决方案。

问题是我没有在我的模型上使用 PHPDoc 注释。

所以我从这个

改变了每个属性
protected $street = '';

至此

/**
 * @var string
 */
protected $street = '';