php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28606 sprintf() function bug with classes
Submitted: 2004-06-02 01:02 UTC Modified: 2004-06-02 11:06 UTC
From: Kmos at GodsFamily dot com Assigned:
Status: Not a bug Package: Compile Warning
PHP Version: 4.3.6 OS: Windows XP SP1
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: Kmos at GodsFamily dot com
New email:
PHP Version: OS:

 

 [2004-06-02 01:02 UTC] Kmos at GodsFamily dot com
Description:
------------
I think there is a bug with sprintf() function when I use it with more than one % to format variable output.

Example:

If I use two %s %s it crashes, but if I use only one %s or static values the sql query is valid and no warning errors happen. I think this is really strange, and I don't think I've mistake my php code, I code for some years..

Reproduce code:
---------------
class bdsql
{
function query($sql="",$vars="")
	{
		$sql=sprintf($sql, $vars);
		$result=@mysql_query($sql);
		
		return $result;
	}
}

class kwww extends bdsql
{
	function load_data($cat="",$scat="",$min=0,$max=10)
	{
		$result=$this->query("SELECT * FROM sites WHERE cat='%s' AND scat='%s' LIMIT %d,%d;","addslashes(htmlentities($cat)), addslashes(htmlentities($scat)), $min, $max");
	}
}

How to use (index.php):
$ret2=$kwww->load_data("computadores","internet",0,5);

Expected result:
----------------
Execute the SQL query with no warning errors...

Actual result:
--------------
Warning: sprintf(): Too few arguments in c:\program files\apache\htdocs\kwww\kwww.php on line 38

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-02 08:20 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

.
 [2004-06-02 10:58 UTC] Kmos at GodsFamily dot com
I don't think it's my code mistake... but ok! it's more fast to send us to support ...
 [2004-06-02 11:06 UTC] derick@php.net
I'm 100% sure it's a code mistake, but as this is NOT a support forum, you'll have to seek help elsewhere.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 14 18:01:28 2024 UTC