0

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?

5
  • Please add the actual error message to the question. Do you have intl extension enabled? Commented Dec 28, 2016 at 15:50
  • error message Attempted to call an undefined method named "replaceTags" of class "Locale". because symfony call another calss with name Locale, I think Commented Dec 28, 2016 at 16:08
  • So what about the extension? Do you confirm php -m | grep intl returns nothing? Commented Dec 28, 2016 at 16:15
  • @AlexBlex I don't think this is linked to symfony Locale, he has custom classes Commented Dec 28, 2016 at 16:16
  • @Alex Blex intl I have intl Commented Dec 28, 2016 at 16:25

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

how to disable extension ?
it depends how you installed it. pecl uninstall intl, apt-get remove php5-intl etc.
If you can find something like intl.ini in php configs, e.g. /etc/php5/mods-available, you can comment it out liek ; extension=intl.ini
0

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

1 Comment

If it was the problem, I'd recommend to use composer to map classes instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.