1--TEST--
2Test readlink() and realpath() functions: usage variation - linkname/filename stored in object(Bug #42038)
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) != 'WIN') {
6    die('skip only for Windows');
7} else {
8    include __DIR__ . '/windows_links/common.inc';
9    skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__);
10}
11?>
12--FILE--
13<?php
14echo "*** Testing readlink() and realpath() : usage variations ***\n";
15$name_prefix = __DIR__;
16$filename = "$name_prefix/readlink_realpath_variation1/home/tests/link/readlink_realpath_variation1.tmp";
17mkdir("$name_prefix/readlink_realpath_variation1/home/tests/link/", 0777, true);
18
19echo "\n*** Testing readlink() and realpath() with linkname stored inside a object ***\n";
20// create a temp file
21$file_handle = fopen($filename, "w");
22fclose($file_handle);
23
24// creating object with members as linkname
25class object_temp {
26  public $linkname;
27  function __construct($link) {
28    $this->linkname = $link;
29  }
30}
31$obj1 = new object_temp("$name_prefix/readlink_realpath_variation1/../././readlink_realpath_variation1/home/readlink_realpath_variation1_link.tmp");
32$obj2 = new object_temp("$name_prefix/readlink_realpath_variation1/home/../..///readlink_realpath_variation1_link.tmp");
33
34echo "\n-- Testing readlink() and realpath() with softlink, linkname stored inside an object --\n";
35// creating the links
36var_dump( symlink($filename, $obj1->linkname) );
37var_dump( readlink($obj1->linkname) );
38var_dump( realpath($obj1->linkname) );
39var_dump( symlink($filename, $obj2->linkname) );
40var_dump( readlink($obj2->linkname) );
41var_dump( realpath($obj2->linkname) );
42
43// deleting the link
44unlink($obj1->linkname);
45unlink($obj2->linkname);
46
47echo "\n-- Testing readlink() and realpath() with hardlink, linkname stored inside an object --\n";
48// creating hard links
49var_dump( link($filename, $obj1->linkname) );
50var_dump( readlink($obj1->linkname) );   // invalid because readlink doesn't work with hardlink
51var_dump( realpath($obj1->linkname) );
52var_dump( link($filename, $obj2->linkname) );
53var_dump( readlink($obj2->linkname) );   // invalid because readlink doesn't work with hardlink
54var_dump( realpath($obj2->linkname) );
55
56// delete the links
57unlink($obj1->linkname);
58unlink($obj2->linkname);
59
60echo "Done\n";
61?>
62--CLEAN--
63<?php
64$name_prefix = __DIR__."/readlink_realpath_variation1";
65unlink("$name_prefix/home/tests/link/readlink_realpath_variation1.tmp");
66rmdir("$name_prefix/home/tests/link/");
67rmdir("$name_prefix/home/tests/");
68rmdir("$name_prefix/home/");
69rmdir("$name_prefix/");
70?>
71--EXPECTF--
72*** Testing readlink() and realpath() : usage variations ***
73
74*** Testing readlink() and realpath() with linkname stored inside a object ***
75
76-- Testing readlink() and realpath() with softlink, linkname stored inside an object --
77bool(true)
78string(%d) "%s%ereadlink_realpath_variation1%ehome%etests%elink%ereadlink_realpath_variation1.tmp"
79string(%d) "%s%ereadlink_realpath_variation1%ehome%etests%elink%ereadlink_realpath_variation1.tmp"
80bool(true)
81string(%d) "%s%ereadlink_realpath_variation1%ehome%etests%elink%ereadlink_realpath_variation1.tmp"
82string(%d) "%s%ereadlink_realpath_variation1%ehome%etests%elink%ereadlink_realpath_variation1.tmp"
83
84-- Testing readlink() and realpath() with hardlink, linkname stored inside an object --
85bool(true)
86string(%d) "%s%ereadlink_realpath_variation1%ehome%ereadlink_realpath_variation1_link.tmp"
87string(%d) "%s%ereadlink_realpath_variation1%ehome%ereadlink_realpath_variation1_link.tmp"
88bool(true)
89string(%d) "%s%ereadlink_realpath_variation1_link.tmp"
90string(%d) "%s%ereadlink_realpath_variation1_link.tmp"
91Done
92