@Valnurat this is a long post, but I hope I can answer some of your questions.  I'm not an expert with this UDF, and learned even more when I was looking at your issues.   Your $aDACL is an empty array in your _MergeDaclToArray function call, that is why you get 0.  You only declare the variable, but did not set a value to it.  That is not what your problem is.  You are using an incorrect function to do what I think you want to do.  You need to use _EditObjectPermissions. This will allow yo