質問

A few questions but I'm sure the answers will be useful for many getting to grips with the relatively new phar.

  1. Is it possible to delete or edit a file inside the phar script, from within the phar script, when it's actually running?

  2. I've noticed that I can change the name of my phar file from examplename.phar to examplename.php and run it in the url and it still works fine. is that right? is that OK to do? is that safe?

  3. Is it better practice to put all your files in the same directory and then phar it, or is it OK to keep all your folders and sub folders and phar it like that - or does it not matter?

  4. can you obfuscate the phar file. or will that ruin it? does all obfuscating have to be done before pharing?

Hopefully a phar expert can answer these. thanks

役に立ちましたか?

解決

  1. The usual setting of PHP is to treat PHAR files as readonly. In fact, you have to change that setting to allow your local copy of PHP to create these files. I doubt they can be changed, I wouldn't bet on it.

  2. The general structure of a PHAR is an initial PHP script part that sets things up, and then a call to __halt_compiler() followed by zipped bytes (after transferring control to a script part already inside the PHAR), so you can do whatever is possible with any PHP script without PHAR, including changing it's name. Note that the bootstrap code of already existing PHAR files might not allow this because of hardcoded filenames, but this is not the general case.

  3. It does not really matter.

  4. Obfuscation on the code level that leave the PHP code in runnable condition with pure PHP won't affect PHAR. Anything that expects PHP to already contain special extensions will probably fail.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top