2
Dear, I have a system where the user (with development permission) can program some online routines, to be executed within the system, without the need to create file and call via require / include.
To perform this function, I use create_function, but the problem is that when creating this function within a loop for example, the error "cannot redeclare class xxxx".
If the routine is created like this: class aaa{/codigo/}
And I make a loop for execution:
for ($i = 1; $i <= 5; $i++) {
$funcao = create_function('', $codigoLidoDoBD);
$funcao();
}
The error occurs because even having a different function name, the aaa class has already been declared and registered somewhere :S
Obs: You could use class_exists in each class, but there are many to change...
Obs2: Sometimes, even declaring the create_function
outside the loop and calling only to $funcao()
, the error also occurs.
Does anyone know how to solve?
Who defines the class name is the system or the user?
– Papa Charlie
This will be a maintenance and security nightmare.
– Maniero
http://stackoverflow.com/questions/20394721/why-is-there-a-function-create-function-php
– Daniel Omine
@Papacharlie who defines is the user himself.
– Diogo
@bigown is not no, because the place where these functions and classes are set is protected by security groups and tals.. what I still need to do is determine when and how the routine can be performed..
– Diogo
@Danielomine is not quite that, but thanks anyway man!
– Diogo
@user3123816 goes for it, the worst part is you don’t know what you’re getting yourself into. You can protect as much as you want, you can use the latest innovation in safety, what you’re doing is intrinsically insecure, and there’s only one way to not create huge maintenance problems if it’s a failure. I’m warning you because I have experience with this scenario but I think you’ll only know if you do and succeed if you’re actually used. See that several people agreed with me.
– Maniero
@user3123816, there seems to be a collision with the class names when you carry two or more with the same name. I believe you have to rename the class. You can use a type ID
class UserFulanoDeTal_ID_01{/codigo/}
. Even if there are 2 classes with the same name, the system will replace to avoid collision.– Papa Charlie
@user3123816, posted the link only to reinforce what others have warned about what you are using.. Often finding a solution to something "crooked" is worse than remaking and undoing..
– Daniel Omine