Generating the property name of an object
Yes, this is bad practice, sometimes

You are giving the user the option to dynamically change object properties. What if the property doesn't exist? What if a boogie monster passes by?

Sometimes, generating the property could be usefull, but only do this when you trust the thing that is generating the property. Is it a user? bad practice. Is it the program itself, wel, maybe.

escaping data

Don't escape data, don't try and remove all 'bad' data. A better approach is to check for a whitelist.

$role has to be an integer, so make sure it is

&lt;?php

if ( preg_match('/^[0-9]+$/',$_POST['role']) != 1 )
{
    throw new Exception('I need an int');
}


feature and permission probably only accept alpha characters? And probably only lower case? So let's check that:



if ( preg_match('/^[0-9a-z]+$/',$_POST['role']) != 1 )
{
    throw new Exception('I need an int');
}


whitelists are better

Use whitelists instead of blacklist. It's easier to know what is allowed then to know what isn't. Simply because we can't know all the bad things out there