summaryrefslogtreecommitdiff
path: root/sapi/phpdbg/tests/phpdbg_get_executable_stream_wrapper.phpt
diff options
context:
space:
mode:
authorBob Weinand <bobwei9@hotmail.com>2016-12-06 18:30:37 +0100
committerBob Weinand <bobwei9@hotmail.com>2016-12-06 18:30:37 +0100
commit43f88f25bbd40c350a5a255eb1ce687d70471ebc (patch)
tree24beaf09af2a89b020e3df65ee5447c4d236a856 /sapi/phpdbg/tests/phpdbg_get_executable_stream_wrapper.phpt
parent308cc2e9d4765b3fbdc89ec4479d4d229c640728 (diff)
parent7e12b5da712f603d4ff68c378c0b1f06dcc495db (diff)
downloadphp-git-43f88f25bbd40c350a5a255eb1ce687d70471ebc.tar.gz
Merge branch 'PHP-7.0' into PHP-7.1
Diffstat (limited to 'sapi/phpdbg/tests/phpdbg_get_executable_stream_wrapper.phpt')
-rw-r--r--sapi/phpdbg/tests/phpdbg_get_executable_stream_wrapper.phpt84
1 files changed, 84 insertions, 0 deletions
diff --git a/sapi/phpdbg/tests/phpdbg_get_executable_stream_wrapper.phpt b/sapi/phpdbg/tests/phpdbg_get_executable_stream_wrapper.phpt
new file mode 100644
index 0000000000..0ddbd6f527
--- /dev/null
+++ b/sapi/phpdbg/tests/phpdbg_get_executable_stream_wrapper.phpt
@@ -0,0 +1,84 @@
+--TEST--
+Getting executable lines from custom wrappers
+--PHPDBG--
+r
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> array(1) {
+ [5]=>
+ int(0)
+}
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+/**
+ * This example demonstrates how phpdbg_get_executable() behaves differently
+ * when passed the 'files' option vs without, in the face of some mild abuse
+ * of stream wrappers.
+ */
+
+/**
+ * First, we define a stream wrapper that simply maps to a real file on disk.
+ */
+final class StreamWrapper
+{
+ public function stream_open(
+ string $path,
+ string $mode,
+ int $options = 0,
+ string &$openedPath = null
+ ) : bool {
+ if ($mode[0] !== 'r') {
+ return false;
+ }
+
+ list($scheme, $path) = explode('://', $path, 2);
+
+ $stream = \fopen($path, $mode);
+
+ if ($stream === false) {
+ return false;
+ }
+
+ $this->stream = $stream;
+
+ /**
+ * The $openedPath reference variable is assigned, indicating the
+ * *actual* path that was opened. This affects the behaviour of
+ * constants like __FILE__.
+ */
+ $openedPath = \realpath($path);
+
+ return true;
+ }
+
+ public function stream_read(int $count) : string { return \fread($this->stream, $count); }
+ public function stream_close() : bool { return \fclose($this->stream); }
+ public function stream_eof() : bool { return \feof($this->stream); }
+ public function stream_stat() { return \fstat($this->stream); }
+
+ private $stream = false;
+}
+
+stream_wrapper_register('wrapper', StreamWrapper::class);
+
+/**
+ * Next, we include a PHP file that contains executable lines, via the stream
+ * wrapper.
+ */
+$filename = __DIR__ . '/phpdbg_get_executable_stream_wrapper.inc';
+require 'wrapper://' . $filename;
+
+/**
+ * If we call phpdbg_get_executable() and pass no options, the realpath of the
+ * included file is present in the array, but indicates no executable lines.
+ */
+$x = phpdbg_get_executable();
+
+// We expect [5 => 0], but got an empty array ...
+var_dump($x[$filename]);
+
+?>