Reputation: 4071
I have app with old code - plain php and new code - Symfony. And when in old code call class symfony autoloader, maybe, intercepts class, how told Symfony to call exctly needed class
I have app/old/core/classes/Locale.php
from old code, without name space and
app/src/AppBundle/Entity/Locale.php
from new code, this is entity with name space
and in old code I call static function Locale from old code, but Symfony call entity, of course entity LOcale dont have this static function and I have error
class Page
{
function replacePageTags($replace_arr)
{
// set brases for keys
$braced_arr = Array();
foreach($replace_arr as $key => $value) {
$braced_arr["{".$key."}"] = $value;
}
//this I have error
$this->content = Locale::replaceTags($this->content, $braced_arr);
}
}
error message:
Attempted to call an undefined method named "replaceTags" of class "Locale".
whe I add include Locale to class Page
include('Locale.php');
class Page
{
have error
Error: Cannot declare class Locale, because the name is already in use
But when I add to entity static function replaceTags($text, $replace_arr)
still have error, maybe Symfony call another Locale, but I need call Locale from old functionality, how can I do this ?
maybe this because in composer in autoload I have
"autoload": {
"psr-4": {
"": "src/"
}
but old code not in src or I dont know
In another developer have not this problem, I have php version 7.0.14, they have 7.0.8, maybe I need low some ph destriction, I don't know ( How to call exectly needed class in old code or fix this problem?
Upvotes: 0
Views: 380
Reputation: 37108
Your Page
class uses \Locale
from intl extension.
The only option you have is to disable the extension as the legacy (namespaceless) code is not compatible with it due to class name collision.
Upvotes: 2
Reputation: 8162
If your old Library does not have namespace, you can use MapClassLoader to do a mapping.
require_once '/path/to/src/Symfony/Component/ClassLoader/MapClassLoader.php';
$mapping = array(
'Foo' => '/path/to/Foo',
'Bar' => '/path/to/Bar',
);
$loader = new MapClassLoader($mapping);
$loader->register();
You can do it automatically on your old code by using the class map generator.
This way you could have a custom namespace like Legacy\Class
for all your old classes
Upvotes: 0