|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
PHP5 - Including php script within class function
This isn't so much a question of why something doesn't work, but rather a question of why it does work. Using PHP you can include scripts from within class functions and access the included functions globally. This surprises me, it seems to go against what I feel should occur. If someone has a sound reason why this occurs, I would appreciate it.
temp_include.php: PHP Code:
main script: PHP Code:
|
|
#2
|
||||
|
||||
|
maybe you can, but the concept is incorrect.. meaning it was not created to work this way.. and things that have not been created to work away... leads to vulnerabilities sometimes.
__________________
IE QUOTE | PHP Manual | Google | C/C++ Compiler | Linux Tutorials | General Stuff Game Dev |
|
#3
|
||||
|
||||
|
http://us2.php.net/manual/en/language.functions.php
Quote:
All you're doing is defining a function inside a function: the fact that it's inside a class too doesn't matter.
__________________
How to ask a question |
|
#4
|
|||
|
|||
|
Yeah, it seems to be somewhat common practice to include this way anyways. I took a look at the source for Smarty and their Smarty_compiler.class.php includes plugins and other files from functions of that class this way.
|
|
#5
|
||||
|
||||
|
Quote:
According to the manual it was created to work that way. If it didn't work that way it would be possible to dynamically add functions to an object; I don't know for sure but I'm pretty sure that doing something like that would requires pretty extensive design changes to the zend engine. Not that it would be a bad thing (javascript supports it and imo javascript's class system is one of the best with the exception of a few small parts of it), but I don't think PHP even could support something like that in its current state. |
|
#6
|
||||
|
||||
|
Ok, off topic question is now: Do you really need to use a class for this or are you just curious?
Chad
__________________
Get A Supplier LLC | Hilarious Comic --- Pretty much retired from the forum. I will get back on every now and then, and maybe answer a few questions. |
|
#7
|
||||
|
||||
|
You don't need to use a class for this. The OP was commenting it was was odd that when you include a file within the scope of a class the functions in the included file are added to the global scope rather than the class scope (as they would if the methods had been hard coded into the class).
|
|
#8
|
|||
|
|||
|
Quote:
For reasons I won't get into, I'm considering of setting up a plugin system into my application. So yeah, this wasn't just something that popped in my head while watching the Jays getting killed. |
|
#9
|
||||
|
||||
|
Quote:
Sorry I misunderstood chadsmith's question, I thought he was asking if you needed a class to use include >< |
|
#10
|
||||
|
||||
|
Quote:
|
|
#11
|
||||
|
||||
|
Topgear:
Ok that's fine, I just had to question that. Because maybe there was another way that you could be doing the project that might be easier and better to maintain. Great, have a good time and hope you find an answer. Chad |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > PHP5 - Including php script within class function |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|