Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_print_r, 0, 0, 1)
ZEND_ARG_INFO(0, return)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_puts, 0, 0, 1)
ZEND_ARG_INFO(0, message)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(arginfo_connection_aborted, 0)
ZEND_END_ARG_INFO()

Expand Down Expand Up @@ -3032,6 +3036,7 @@ static const zend_function_entry basic_functions[] = { /* {{{ */
PHP_FE(var_export, arginfo_var_export)
PHP_FE(debug_zval_dump, arginfo_debug_zval_dump)
PHP_FE(print_r, arginfo_print_r)
PHP_FE(puts, arginfo_puts)
PHP_FE(memory_get_usage, arginfo_memory_get_usage)
PHP_FE(memory_get_peak_usage, arginfo_memory_get_peak_usage)

Expand Down Expand Up @@ -5645,6 +5650,20 @@ PHP_FUNCTION(print_r)
}
/* }}} */

/* {{{ proto void puts(string message) */
PHP_FUNCTION(puts)
{
zend_string *message;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR(message)
ZEND_PARSE_PARAMETERS_END();

PHPWRITE(ZSTR_VAL(message), ZSTR_LEN(message));
PHPWRITE(PHP_EOL, sizeof(PHP_EOL) - 1);
}
/* }}} */

/* {{{ proto int connection_aborted(void)
Returns true if client disconnected */
PHP_FUNCTION(connection_aborted)
Expand Down
1 change: 1 addition & 0 deletions ext/standard/basic_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ PHP_FUNCTION(set_include_path);
PHP_FUNCTION(restore_include_path);

PHP_FUNCTION(print_r);
PHP_FUNCTION(puts);
PHP_FUNCTION(fprintf);
PHP_FUNCTION(vfprintf);

Expand Down
79 changes: 79 additions & 0 deletions ext/standard/tests/strings/puts.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
--TEST--
Test puts() function : basic functionality
--FILE--
<?php

/* Prototype : void puts ( string $arg )
* Description: Output a string
* Source code: ext/standard/basic_functions.c
*/

echo "*** Testing puts() : basic functionality ***\n";

echo "-- Iteration 1 --\n";
puts("Hello World");

echo "-- Iteration 2 --\n";
puts("This spans
multiple lines. The newlines will be
output as well");

echo "-- Iteration 3 --\n";
puts("escaping characters is done \"Like this\".");

// You can use variables inside of a puts statement
$foo = "foobar";
$bar = "barbaz";

echo "-- Iteration 4 --\n";
puts("foo is $foo"); // foo is foobar

// You can also use arrays
$bar = array("value" => "foo");

echo "-- Iteration 5 --\n";
puts("this is {$bar['value']} !"); // this is foo !

// Using single quotes will output the variable name, not the value
echo "-- Iteration 6 --\n";
puts('foo is $foo'); // foo is $foo

// If you are not using any other characters, you can just output variables
echo "-- Iteration 7 --\n";
puts($foo); // foobar

echo "-- Iteration 8 --\n";
$variable = "VARIABLE";
puts(<<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon no extra whitespace!
END
);
?>
===DONE===
--EXPECT--
*** Testing puts() : basic functionality ***
-- Iteration 1 --
Hello World
-- Iteration 2 --
This spans
multiple lines. The newlines will be
output as well
-- Iteration 3 --
escaping characters is done "Like this".
-- Iteration 4 --
foo is foobar
-- Iteration 5 --
this is foo !
-- Iteration 6 --
foo is $foo
-- Iteration 7 --
foobar
-- Iteration 8 --
This uses the "here document" syntax to output
multiple lines with VARIABLE interpolation. Note
that the here document terminator must appear on a
line with just a semicolon no extra whitespace!
===DONE===