The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
How does "Execution Order" in PHP code function?
I closed / removed my previous thread regarding this, thinking I wouldn't be needing it anymore.. but I think I was wrong. I've wrote a code, and give each of them an Execution order number..
First one: 1 Second plugin: 2 Running a very identical code, with: Code:
$dataman->set('usergroupid', xx); Now.. the question is, why is the second one being executed faster then the first one? I included a: Code:
IF $vbulletin->userinfo['usergroupid'] == xx) |
#2
|
||||
|
||||
I'm not sure I'm following you.
The execution order is just the order of execution (sorry to state the obvious), meaning: execution order 1: executed first. execution order 2: executed second. The same as if you would put both codes into a php file one after the other, or if you would put both code lines into one plugin. If you run virtually the same code with just a different value, than the second run will just overwrite the first. |
#3
|
|||
|
|||
Already mentioned that in my post at the bottom:
Quote:
Part of the first code: Code:
$dataman =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD); $dataman->set_existing($vbulletin->userinfo); if xxxxxx AND $vbulletin->userinfo['usergroupid'] == 13) { $dataman->set('usergroupid', 47); $dataman->save(); } Code:
$dataman =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD); $dataman->set_existing($vbulletin->userinfo); if xxxx AND $vbulletin->userinfo['usergroupid'] == 13) { $dataman->set('usergroupid', 37); $dataman->save(); } |
#4
|
|||
|
|||
Well, like cellarius said, it's just the order they are executed in. All the code for all plugins on a given hook gets built in to one string, according to the execution order, then it's exec'd when that hook is reached. I've never heard anyone complain that the execution order didn't work right.
Is there a reason you have more than one plugin on a hook, rather than putting it all in one? I've done that myself sometimes just to organize things, but if you're having problems you could try putting it all in one plugin. In any case, we'd probably have to see more code to help you figure out what's going on. |
#5
|
|||
|
|||
As you mentioned, doing it to organize things. Easier overview. I've put 'most' of the code in the above post (as an edit).. the xxx's are just other variables to check. But that's stating the obvious. The xxx's in both are almost identical, except for 1 check. But dunno why the second would beat the first execution order.
|
#6
|
|||
|
|||
So how did you determine that they were running in the wrong order?
If you wanted to you could actually see the code that's being executed by using something like var_dump($hook). |
#7
|
|||
|
|||
Quote:
I'm not a 'pro' regarding all of this.. Still learning, that's for sure. Never used var_dump($hook) before, would the code display on a single page and only that single plugin? or.... |
#8
|
|||
|
|||
Yeah, using var_dump() will output whenever the code is run, and the way vbulletin works is it builds all the output into a string then sends it at the end, so the result would be that something you print out will come out before anything else and likely cause errors as well. Sometimes for debugging i do something like var_dump() a variable then call die, and you'll get a page with nothing else on it, but of course you only want to do that on a test forum. You could also open a file and write stuff to it, then look at the file after. Anyway, if you do decide to try to display that, $hook has all the code for that hook so you only need to var_dump it in one of the plugins.
You might want to temporarily put all the code in one plugin and disable the others, just to rule out the multiple plugins as a potential source of the problem. |
#9
|
|||
|
|||
Guess I'll combine them instead with if/else. Works for me, but finding it very strange the execution order is not working properly.
|
#10
|
|||
|
|||
Oh, wait. were you saying that you depend on $vbulletin->userinfo['usergroupid'] == 13 being false in the second one to prevent it from running if the first one already did? Because using the datamanager to change the usergroup will not change $vbulletin->userinfo['usergroupid'] (I don't think).
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|