Loading multiple versions of the same class

前端 未结 3 1643
一整个雨季
一整个雨季 2020-12-17 01:05

Let\'s say I release a code library as a standalone PHP class. Someone then uses version 1.0 of that library in their application. Later, I release version 2.0 of the libr

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 01:44

    So is there a way to dynamically create a namespace, include a file, and instantiate the class contained within that file in a uniquely-named variable?

    Yes, such method exists. You can do anything you want with eval and stream handlers. But it is bad practice and wrong approach - you can try to use factory method (the code is not tested - it only shows example):

提交回复
热议问题