Skip to content

Commit e09fab9

Browse files
committed
adding vsprintf to deprecated
1 parent e2cd5cb commit e09fab9

File tree

2 files changed

+302
-0
lines changed

2 files changed

+302
-0
lines changed

deprecated/functionsList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@
6464
'stats_variance',
6565
'substr',
6666
'usort',
67+
'vsprintf',
6768
];

deprecated/strings.php

Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,304 @@ function substr(string $string, int $start, int $length = null): string
374374
}
375375
return $result;
376376
}
377+
378+
/**
379+
* Operates as sprintf but accepts an array of
380+
* arguments, rather than a variable number of arguments.
381+
*
382+
* @param string $format The format string is composed of zero or more directives:
383+
* ordinary characters (excluding %) that are
384+
* copied directly to the result and conversion
385+
* specifications, each of which results in fetching its
386+
* own parameter.
387+
*
388+
* A conversion specification follows this prototype:
389+
* %[argnum$][flags][width][.precision]specifier.
390+
*
391+
* An integer followed by a dollar sign $,
392+
* to specify which number argument to treat in the conversion.
393+
*
394+
*
395+
* Flags
396+
*
397+
*
398+
*
399+
* Flag
400+
* Description
401+
*
402+
*
403+
*
404+
*
405+
* -
406+
*
407+
* Left-justify within the given field width;
408+
* Right justification is the default
409+
*
410+
*
411+
*
412+
* +
413+
*
414+
* Prefix positive numbers with a plus sign
415+
* +; Default only negative
416+
* are prefixed with a negative sign.
417+
*
418+
*
419+
*
420+
* (space)
421+
*
422+
* Pads the result with spaces.
423+
* This is the default.
424+
*
425+
*
426+
*
427+
* 0
428+
*
429+
* Only left-pads numbers with zeros.
430+
* With s specifiers this can
431+
* also right-pad with zeros.
432+
*
433+
*
434+
*
435+
* '(char)
436+
*
437+
* Pads the result with the character (char).
438+
*
439+
*
440+
*
441+
*
442+
*
443+
*
444+
* An integer that says how many characters (minimum)
445+
* this conversion should result in.
446+
*
447+
* A period . followed by an integer
448+
* who's meaning depends on the specifier:
449+
*
450+
*
451+
*
452+
* For e, E,
453+
* f and F
454+
* specifiers: this is the number of digits to be printed
455+
* after the decimal point (by default, this is 6).
456+
*
457+
*
458+
*
459+
*
460+
* For g and G
461+
* specifiers: this is the maximum number of significant
462+
* digits to be printed.
463+
*
464+
*
465+
*
466+
*
467+
* For s specifier: it acts as a cutoff point,
468+
* setting a maximum character limit to the string.
469+
*
470+
*
471+
*
472+
*
473+
*
474+
* If the period is specified without an explicit value for precision,
475+
* 0 is assumed.
476+
*
477+
*
478+
*
479+
*
480+
* Specifiers
481+
*
482+
*
483+
*
484+
* Specifier
485+
* Description
486+
*
487+
*
488+
*
489+
*
490+
* %
491+
*
492+
* A literal percent character. No argument is required.
493+
*
494+
*
495+
*
496+
* b
497+
*
498+
* The argument is treated as an integer and presented
499+
* as a binary number.
500+
*
501+
*
502+
*
503+
* c
504+
*
505+
* The argument is treated as an integer and presented
506+
* as the character with that ASCII.
507+
*
508+
*
509+
*
510+
* d
511+
*
512+
* The argument is treated as an integer and presented
513+
* as a (signed) decimal number.
514+
*
515+
*
516+
*
517+
* e
518+
*
519+
* The argument is treated as scientific notation (e.g. 1.2e+2).
520+
* The precision specifier stands for the number of digits after the
521+
* decimal point since PHP 5.2.1. In earlier versions, it was taken as
522+
* number of significant digits (one less).
523+
*
524+
*
525+
*
526+
* E
527+
*
528+
* Like the e specifier but uses
529+
* uppercase letter (e.g. 1.2E+2).
530+
*
531+
*
532+
*
533+
* f
534+
*
535+
* The argument is treated as a float and presented
536+
* as a floating-point number (locale aware).
537+
*
538+
*
539+
*
540+
* F
541+
*
542+
* The argument is treated as a float and presented
543+
* as a floating-point number (non-locale aware).
544+
* Available as of PHP 5.0.3.
545+
*
546+
*
547+
*
548+
* g
549+
*
550+
*
551+
* General format.
552+
*
553+
*
554+
* Let P equal the precision if nonzero, 6 if the precision is omitted,
555+
* or 1 if the precision is zero.
556+
* Then, if a conversion with style E would have an exponent of X:
557+
*
558+
*
559+
* If P > X ≥ −4, the conversion is with style f and precision P − (X + 1).
560+
* Otherwise, the conversion is with style e and precision P − 1.
561+
*
562+
*
563+
*
564+
*
565+
* G
566+
*
567+
* Like the g specifier but uses
568+
* E and f.
569+
*
570+
*
571+
*
572+
* o
573+
*
574+
* The argument is treated as an integer and presented
575+
* as an octal number.
576+
*
577+
*
578+
*
579+
* s
580+
*
581+
* The argument is treated and presented as a string.
582+
*
583+
*
584+
*
585+
* u
586+
*
587+
* The argument is treated as an integer and presented
588+
* as an unsigned decimal number.
589+
*
590+
*
591+
*
592+
* x
593+
*
594+
* The argument is treated as an integer and presented
595+
* as a hexadecimal number (with lowercase letters).
596+
*
597+
*
598+
*
599+
* X
600+
*
601+
* The argument is treated as an integer and presented
602+
* as a hexadecimal number (with uppercase letters).
603+
*
604+
*
605+
*
606+
*
607+
*
608+
*
609+
* General format.
610+
*
611+
* Let P equal the precision if nonzero, 6 if the precision is omitted,
612+
* or 1 if the precision is zero.
613+
* Then, if a conversion with style E would have an exponent of X:
614+
*
615+
* If P > X ≥ −4, the conversion is with style f and precision P − (X + 1).
616+
* Otherwise, the conversion is with style e and precision P − 1.
617+
*
618+
* The c type specifier ignores padding and width
619+
*
620+
* Attempting to use a combination of the string and width specifiers with character sets that require more than one byte per character may result in unexpected results
621+
*
622+
* Variables will be co-erced to a suitable type for the specifier:
623+
*
624+
* Type Handling
625+
*
626+
*
627+
*
628+
* Type
629+
* Specifiers
630+
*
631+
*
632+
*
633+
*
634+
* string
635+
* s
636+
*
637+
*
638+
* integer
639+
*
640+
* d,
641+
* u,
642+
* c,
643+
* o,
644+
* x,
645+
* X,
646+
* b
647+
*
648+
*
649+
*
650+
* double
651+
*
652+
* g,
653+
* G,
654+
* e,
655+
* E,
656+
* f,
657+
* F
658+
*
659+
*
660+
*
661+
*
662+
*
663+
* @param array $args
664+
* @return string Return array values as a formatted string according to
665+
* format.
666+
* @throws StringsException
667+
* @deprecated The Safe version of this function is no longer needed in PHP 8.0+
668+
*/
669+
function vsprintf(string $format, array $args): string
670+
{
671+
error_clear_last();
672+
$result = \vsprintf($format, $args);
673+
if ($result === false) {
674+
throw StringsException::createFromPhpError();
675+
}
676+
return $result;
677+
}

0 commit comments

Comments
 (0)