Is it possible to isolate constants in different PHP namespaces?

60
July 21, 2021, at 10:00 AM

I'm working on the PHP Project which is encrypted. It provides the main php file which including all the functions like get information and rendering the UI.

main.php

// Encrypted, for explaining only. Cannot be edited
require "Smarty.class.php";
include ..
...
..
$template = new Smarty();
$database =......

index.php

// Can edit
include "main.php";
$user = $database->getUser();
$template->assign("user",$user);
$template->display("index.php");
// Other Codes
if(!$user['activate']){
 $email->send...
}
...
...

However, the Smarty (Template Library) version is too old, and the project seems edited and encrypted the original code, so I cannot fix it and the online document cannot help.

So I decided to download the official version of smarty to replace it.

index.php

include "main.php";
require "new/Smarty.class.php";
$new_template = new Smarty();

However, the name of Smarty Class is duplicated. So I try to use namespace to fix it.

custom.php

namespace test{
    require "new\Smarty.class.php";
    class Smarty extends \Smarty{
     // Keep all original setting
    }
}

index.php

include "main.php";
include "custom.php";
$new_template = new test\Smarty();

Now, the new Smarty class is able to defined. But I check the Smarty have many code like this

if (!defined('SMARTY_DIR')) {
    /**
     *
     */
    define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
}

The constant cannot be delete or edit. So It loaded the old variable and make some error (like required plugin not found)

Is there any solution to separate two library ?

READ ALSO
Creating histogram from list

Creating histogram from list

This question was a part of the the interview process and I couldn't figure it outGiven a list of integers, create a histogram where the output is a dictionary

74
I keep getting Error: ER_EMPTY_QUERY: QUERY was empty

I keep getting Error: ER_EMPTY_QUERY: QUERY was empty

I'm trying to make a register pageWhen I enter the data that needs to be registered, it shows up on the console followed by Error: ER_EMPTY_QUERY

49
Javascript Operators - Combining Nullish Coalescing with Ternary

Javascript Operators - Combining Nullish Coalescing with Ternary

So I have some code where I'm essentially trying to do an if, else if, else statement in one line, but based on nullishness instead of truthiness

58
Django - JQuery autocomplete custom select from multiple fields

Django - JQuery autocomplete custom select from multiple fields

I have a user search that autocompletes by both ticker and nameThe search results come back as "{{ticker}} - {{name}}"

80