diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index ff5f11de4a598..ae6e1b1a9abb7 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -758,6 +758,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_println, 0, 0, 1) + ZEND_ARG_INFO(0, message) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO(arginfo_connection_aborted, 0) ZEND_END_ARG_INFO() @@ -3027,6 +3031,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(println, arginfo_println) PHP_FE(memory_get_usage, arginfo_memory_get_usage) PHP_FE(memory_get_peak_usage, arginfo_memory_get_peak_usage) @@ -5655,6 +5660,20 @@ PHP_FUNCTION(print_r) } /* }}} */ +/* {{{ proto void println(string message) */ +PHP_FUNCTION(println) +{ + 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) diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index 9c949e166c1ea..413933eb54141 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -101,6 +101,7 @@ PHP_FUNCTION(set_include_path); PHP_FUNCTION(restore_include_path); PHP_FUNCTION(print_r); +PHP_FUNCTION(println); PHP_FUNCTION(fprintf); PHP_FUNCTION(vfprintf); diff --git a/ext/standard/tests/strings/println.phpt b/ext/standard/tests/strings/println.phpt new file mode 100644 index 0000000000000..dd4059087ee20 --- /dev/null +++ b/ext/standard/tests/strings/println.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test println() function : basic functionality +--FILE-- + "foo"); + +echo "-- Iteration 5 --\n"; +println("this is {$bar['value']} !"); // this is foo ! + +// Using single quotes will output the variable name, not the value +echo "-- Iteration 6 --\n"; +println('foo is $foo'); // foo is $foo + +// If you are not using any other characters, you can just output variables +echo "-- Iteration 7 --\n"; +println($foo); // foobar + +echo "-- Iteration 8 --\n"; +$variable = "VARIABLE"; +println(<< +===DONE=== +--EXPECT-- +*** Testing println() : 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===