调试“spl_object_hash()期望参数1为对象,给定整数”

时间:2015-03-24 16:02:58

标签: php symfony doctrine-orm

更新了一些Symfony 2软件包之后,我突然遇到了这个错误spl_object_hash() expects parameter 1 to be object, null given。它发生在之前,每次调试它都是一次冒险。

只有当$em->persist($ra)的类型为$entity时,才会调用Bla\OrmBundle\Entity\TapApplianceComponent。对我来说,$ra对象包含的值看起来有效。

有什么想法吗?

        $ra->getLocation()->addComponent($entity);
        $entity->setLocation($ra->getLocation());

        switch (get_class($entity)) {
            case 'Bla\OrmBundle\Entity\TapApplianceComponent':
                $ra->getTapsAndAppliances()->addTapApplianceComponent($entity);
                $entity->setTapsAndAppliances($ra->getTapsAndAppliances());
                break;
            default:
        }

        $em->persist($ra);
        $em->persist($entity);
        $em->flush();

我有一个类似下面的堆栈跟踪:

exception 'PHPUnit_Framework_Error_Warning' with message 'spl_object_hash() expects parameter 1 to be object, null given' in C:\xampp\htdocs\TestServer\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php:1602
Stack trace:
#0 [internal function]: PHPUnit_Util_ErrorHandler::handleError(2, 'spl_object_hash...', 'C:\\xampp\\htdocs...', 1602, Array)
#1 C:\xampp\htdocs\TestServer\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php(1602): spl_object_hash(NULL)
#2 C:\xampp\htdocs\TestServer\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php(2219): Doctrine\ORM\UnitOfWork->doPersist(NULL, Array)
#3 C:\xampp\htdocs\TestServer\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php(1645): Doctrine\ORM\UnitOfWork->cascadePersist(Object(Bla\OrmBundle\Entity\TapApplianceComponent), Array)
#4 C:\xampp\htdocs\TestServer\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php(2219): Doctrine\ORM\UnitOfWork->doPersist(Object(Bla\OrmBundle\Entity\TapApplianceComponent), Array)
#5 C:\xampp\htdocs\TestServer\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php(1645): Doctrine\ORM\UnitOfWork->cascadePersist(Object(Bla\OrmBundle\Entity\TapsAndAppliances), Array)
#6 C:\xampp\htdocs\TestServer\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php(2224): Doctrine\ORM\UnitOfWork->doPersist(Object(Bla\OrmBundle\Entity\TapsAndAppliances), Array)
#7 C:\xampp\htdocs\TestServer\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php(1645): Doctrine\ORM\UnitOfWork->cascadePersist(Object(Bla\OrmBundle\Entity\AutoRa), Array)
#8 C:\xampp\htdocs\TestServer\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php(1583): Doctrine\ORM\UnitOfWork->doPersist(Object(Bla\OrmBundle\Entity\AutoRa), Array)
#9 C:\xampp\htdocs\TestServer\vendor\doctrine\orm\lib\Doctrine\ORM\EntityManager.php(546): Doctrine\ORM\UnitOfWork->persist(Object(Bla\OrmBundle\Entity\AutoRa))
#10 C:\xampp\htdocs\TestServer\src\Bla\ApiBundle\Controller\DefaultController.php(217): Doctrine\ORM\EntityManager->persist(Object(Bla\OrmBundle\Entity\AutoRa))
#11 [internal function]: Bla\ApiBundle\Controller\DefaultController->postComponentAction(Object(Symfony\Component\HttpFoundation\Request), '1')
#12 C:\xampp\htdocs\TestServer\app\bootstrap.php.cache(3008): call_user_func_array(Array, Array)
#13 C:\xampp\htdocs\TestServer\app\bootstrap.php.cache(2970): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#14 C:\xampp\htdocs\TestServer\app\bootstrap.php.cache(3119): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#15 C:\xampp\htdocs\TestServer\app\bootstrap.php.cache(2364): Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#16 C:\xampp\htdocs\TestServer\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Client.php(81): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#17 C:\xampp\htdocs\TestServer\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Client.php(111): Symfony\Component\HttpKernel\Client->doRequest(Object(Symfony\Component\HttpFoundation\Request))
#18 C:\xampp\htdocs\TestServer\vendor\symfony\symfony\src\Symfony\Component\BrowserKit\Client.php(327): Symfony\Bundle\FrameworkBundle\Client->doRequest(Object(Symfony\Component\HttpFoundation\Request))
#19 C:\xampp\htdocs\TestServer\src\Bla\ApiBundle\Tests\Controller\ComponentControllerTest.php(57): Symfony\Component\BrowserKit\Client->request('POST', '/api2/analyses/...', Array, Array, Array)
#20 [internal function]: Bla\ApiBundle\Tests\Controller\ComponentControllerTest->testPostIssueES862()
#21 C:\xampp\htdocs\TestServer\vendor\phpunit\phpunit\src\Framework\TestCase.php(962): ReflectionMethod->invokeArgs(Object(Bla\ApiBundle\Tests\Controller\ComponentControllerTest), Array)
#22 C:\xampp\htdocs\TestServer\vendor\phpunit\phpunit\src\Framework\TestCase.php(826): PHPUnit_Framework_TestCase->runTest()
#23 C:\xampp\htdocs\TestServer\vendor\phpunit\phpunit\src\Framework\TestResult.php(686): PHPUnit_Framework_TestCase->runBare()
#24 C:\xampp\htdocs\TestServer\vendor\phpunit\phpunit\src\Framework\TestCase.php(760): PHPUnit_Framework_TestResult->run(Object(Bla\ApiBundle\Tests\Controller\ComponentControllerTest))
#25 C:\xampp\htdocs\TestServer\vendor\phpunit\phpunit\src\Framework\TestSuite.php(699): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
#26 C:\xampp\htdocs\TestServer\vendor\phpunit\phpunit\src\Framework\TestSuite.php(699): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#27 C:\xampp\htdocs\TestServer\vendor\phpunit\phpunit\src\TextUI\TestRunner.php(426): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#28 C:\xampp\php\pear\PHPUnit\TextUI\Command.php(176): PHPUnit_TextUI_TestRunner->doRun(Object(NetBeansSuite), Array)
#29 C:\xampp\php\pear\PHPUnit\TextUI\Command.php(129): PHPUnit_TextUI_Command->run(Array, true)
#30 C:\xampp\php\phpunit(46): PHPUnit_TextUI_Command::main()

0 个答案:

没有答案