php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #14112 sprintf_array()
Submitted: 2001-11-19 05:46 UTC Modified: 2001-11-19 08:50 UTC
From: lenar at vision dot ee Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.1.0RC1 OS: Linux
Private report: No CVE-ID: None
 [2001-11-19 05:46 UTC] lenar at vision dot ee
Hi,

During development i felt great need for function
that could be named sprintf_array()

That is ordinary sprintf() which would be able
to take arguments from array:

string sprintf_array(string format, array args)

What do you think?

Lenar

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-19 05:53 UTC] zak@php.net
Why not just build your own function?

function sprintf_array ($format) {
	if (1 == func_get_args () ) {
		return sprintf ($format);
	}

	$argv = func_get_args ();
	return call_user_func_array ('sprintf', $argv);
}

(Not tested, but something like this should work. :)

 [2001-11-19 06:11 UTC] lenar at vision dot ee
Yes something like this should work.

But it's not as fast as it could be.
And I personally like when thins are as fast
as possible.

 [2001-11-19 06:47 UTC] zak@php.net
I would guess that implementing it as a native PHP 
function would be at least 2x as fast.

I suppose the issue now is finding out if the core PHP 
developers consider the function to have enough value to 
add it.

My personal, non-core developer, opinion is that I don't 
like the idea of adding this function.

Perhaps instead we could overload the current 
implementations of printf and sprintf so that they can 
accept a single-dimension array as the second parameter 
(and in this case, final, parameter)?

 [2001-11-19 07:09 UTC] lenar at vision dot ee
Your solution seems fine to me.
It doesn't change the functionality I requested, so no 
objections.

 [2001-11-19 07:11 UTC] zak@php.net
Poof! Apparently Andrei is prescient. :)

Use vprintf() and vsprintf() to do exactly what you 
requested.

 [2001-11-19 08:00 UTC] lenar at vision dot ee
Not finding anything about those functions [vprintf(), 
vsprintf()] in documentation..



 [2001-11-19 08:05 UTC] lenar at vision dot ee
Already coing to be documented (according to newsgroup 
messages).
Sorry. Closing again.

 [2001-11-19 08:50 UTC] derick@php.net
It's now documented
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 09:01:27 2025 UTC