php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22097 Eval fails to process this gem.
Submitted: 2003-02-06 16:43 UTC Modified: 2003-02-06 17:30 UTC
From: tdrake at tymail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.0 OS: Linux x86 2.4.18
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tdrake at tymail dot com
New email:
PHP Version: OS:

 

 [2003-02-06 16:43 UTC] tdrake at tymail dot com
$error["1231"] = "invalid";
$error["1255"] = "invalid_max";

$invalid     = 'You did not choose a valid quantity for item number $item.\n';
$invalid_min = 'You did not order the minimum amount for item $item.\n';
$invalid_max = 'You ordered more than you were permitted for item $item.\n';

while (list($item, $errortype) = each($error)) {
    eval("\$errormessage .= \"$$errortype\";");
}

print $errormessage;

Eval prints the following:
You did not choose a valid quantity for item number $item.
You ordered more than you were permitted for item $item.

It should print this:
You did not choose a valid quantity for item number 1231.
You ordered more than you were permitted for item 1255.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-06 17:28 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You need to double evaluate.
$$errortype resolves to $invalid
evaluating resolves to the string containing $number.
That has to be evaluated as well.

Also why not use foreach and you can use eval()\'s
return value. See below:

<?php
$errormessage = \"\";

$error[\"1231\"] = \"invalid\";
$error[\"1255\"] = \"invalid_max\";

$invalid     = \'You did not choose a valid quantity for item number $item.\\n\';
$invalid_min = \'You did not order the minimum amount for item $item.\\n\';
$invalid_max = \'You ordered more than you were permitted for item $item.\\n\';

//while (list($item, $errortype) = each($error)) {
foreach($error as $item=>$errortype) {
   	$errormessage .= eval(\"echo eval(\\\"echo \\\\\\\"$$errortype\\\\\\\";\\\");\");
}

echo $errormessage;
?

Send further questions please php-general@lists.php.net
 [2003-02-06 17:30 UTC] helly@php.net
CAUTION: The input field scrambled my input!

You have to use 
- 3 slashes where it shows 7
- 1 slash where it shows 3
- 0 slash where it shows 1
 [2003-02-07 10:26 UTC] tdrake at tymail dot com
This doesn't work as expected.  ($errormessage never actually gets set for some reason.)  But the double eval appears to work like it should.

I also tried:
eval("\$errormessage .= eval(\"echo \\\"$$errortype\\\";\";"); and it still didn't work.
 [2003-02-07 10:34 UTC] tdrake at tymail dot com
meant to type:
eval("\$errormessage .= eval(\"echo \\\"$$errortype\\\";\");");
in the above example.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Feb 12 02:00:01 2026 UTC