mercredi 11 mars 2015

Strange reflection behavior in php Laravel 4

This seems like a fairly simple reflection problem, yet I can't figure it our. I use Laravel 4.2 on Debian with PHP 5.6.6-1.


Basicly what happens is that I want to spawn a new object from a class in a Laravel QueueHandler like so:



$className = 'MyClass';
$myobject = new $className ();


and this doesn't work. I tried everything I can possibly think of and have no clue where to look. This code doesn;t work while it should:



<?php
use Pronamic\Twinfield\Secure\Config;
use Pronamic\Twinfield\Customer\CustomerFactory;

class TwinfieldQueueHandler {
private $twinfieldConfig = null;


...



try {
$twinfieldFactoryClass = 'CustomerFactory';

//returns 0
echo strcmp('CustomerFactory', $twinfieldFactoryClass);

//works
$test0 = new CustomerFactory ($this->twinfieldConfig);

//throws an exeption with message: "Class CustomerFactory does not exist"
$r = new ReflectionClass($twinfieldFactoryClass);
$test1 = $r->newInstanceArgs($this->twinfieldConfig);

//gives error PHP Fatal error: Class 'CustomerFactory' not found in {file} on line {line}
$test2 = new $twinfieldFactoryClass ($this->twinfieldConfig);

} catch (Exception $e) {
Log::error($e->getMessage());
}


Has anyone got any pointers on where to look and how to debug this?






Aucun commentaire:

Enregistrer un commentaire