r107054 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107053‎ | r107054 | r107055 >
Date:11:06, 22 December 2011
Author:hashar
Status:reverted (Comments)
Tags:
Comment:
do not evaluate '<?php' line

This happen when you are sending to eval.php a php file. The first line
is the string '<?php' which is passed to eval(). Boom!
This patch skip that string.

Example usage:
$ cat somefile.php
<?php
echo "Working!\n";
$

$ cat somefile.php | php maintenance/eval.php
Working!
$
Modified paths:
  • /trunk/phase3/maintenance/eval.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/eval.php
@@ -74,6 +74,11 @@
7575 readline_add_history( $line );
7676 readline_write_history( $historyFile );
7777 }
 78+ if( false !== strpos($line, "<?php") ) {
 79+ # Someone send a .php file to STDIN so we do not want
 80+ # to interprate the special '<?php'.
 81+ continue;
 82+ }
7883 $val = eval( $line . ";" );
7984 if ( wfIsHipHop() || is_null( $val ) ) {
8085 echo "\n";

Follow-up revisions

RevisionCommit summaryAuthorDate
r107055Fixed a typo in r107054maxsem11:11, 22 December 2011
r107952Revert r107054: breaks execution of lines that might test or output '<?php' s...brion22:29, 3 January 2012

Comments

#Comment by Nikerabbit (talk | contribs)   11:11, 22 December 2011

Why would you want to evaluate a php file this way?

#Comment by Hashar (talk | contribs)   11:38, 22 December 2011

When using eval.php, I write the commands in a file ending with .php. My editor requires the first line to be '<?php' to enable syntax coloring :-)

#Comment by Nikerabbit (talk | contribs)   12:12, 22 December 2011

Can't you just make the first line '#<?php' ?

#Comment by Hashar (talk | contribs)   14:39, 22 December 2011

The file is also included,so you don't want to output # or whatever.

#Comment by Nikerabbit (talk | contribs)   15:10, 22 December 2011

Included where? What are you trying to do? Why not make them maintenance scripts?

#Comment by Hashar (talk | contribs)   23:49, 22 December 2011

Cause when I am hacking I just don't want to write a maintenance script. I usually start using eval.php in interactive mode.

Eventually I have to copy pasting or rewriting the same commands over and over. So I end up pasting that in a text file and using cat file | php eval.php

Today, I have spend too much time figuring out an issue that would have made been obvious if I had syntax coloring. So I did that quick hack and committed it figuring out it might help other devs.

#Comment by Nikerabbit (talk | contribs)   14:02, 23 December 2011

Maybe use a --file param then?

#Comment by Hashar (talk | contribs)   20:12, 23 December 2011

Good idea! We could include() any file given as a parameter. That would solve the <?php issue :D

#Comment by MaxSem (talk | contribs)   11:13, 22 December 2011

What if the file is badly written and starts with something like <?php echo 'foo'; ?

#Comment by Hashar (talk | contribs)   11:39, 22 December 2011

You get kaboom. But since whoever that will do that is probably a developer, that person can amend my change so eval.php supports that syntax 8-)

#Comment by MaxSem (talk | contribs)   11:40, 22 December 2011

Including the removal of initial <?php ;)

#Comment by Brion VIBBER (talk | contribs)   22:27, 3 January 2012

Eh, won't this also kill anything that mentions '<?php' in it?

 $ php maintenance/eval.php 
 > echo '<?php';
 > 

broken! :(

#Comment by Brion VIBBER (talk | contribs)   22:29, 3 January 2012

Reverted in r107952.

Status & tagging log