|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-04-08 18:53 UTC] jeremy dot tharp at gmail dot com
Description:
------------
This isn't really a bug, but I think it would be great to have a control structure that has temporary execution parameters. Consider it an execution space similar to a while or switch, etc.
The reason I could use it in this particular instance is for security reasons. For certain code, I need to elevate a logged in user's "status" to temporarily give them super user permissions. Basically I temporarily convert the user, run the code, then convert them back.
convert_user();
execute_code_here();
convert_user_back();
This works great, of course, but if I have to do this 300 times, there is a decent chance that I would forget to convert_user_back();, causing a security hole (the user would then be logged in as a super user).
It would be great if I could do something like
execspace conversion_space ($params[]) {
function start () {
convert_user();
}
function stop () {
convert_user_back();
}
}
Then in my actual code, I would do:
conversion_space { // start function executes here
// execute some code
} // stop function executes here
This way, it is grammatically impossible to implement the structure without closing it.
I think this would be a powerful control structure for the language. Perhaps there is an equally useful solution that I am unaware of, but if not, I think implementing it is worth consideration (and if there is, I would certainly appreciate the enlightenment!)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 23:00:01 2025 UTC |
A "bit" late, but anyway: as of PHP 5.3 you could make use of a closure, and write conversion_space as a function function conversion_space($func) { convert_user(); $func(); convert_user_back(); } which can be called like so: conversion_space(function () { // some code });