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 no symlinks on Windows');
7}
8?>
9--FILE--
10<?php
11/* Prototype: string readlink ( string $path );
12   Description: Returns the target of a symbolic link
13
14   Prototype: string realpath ( string $path );
15   Description: Returns canonicalized absolute pathname
16*/
17
18echo "*** Testing readlink() and realpath() : usage variations ***\n";
19$name_prefix = dirname(__FILE__);
20$filename = "$name_prefix/readlink_realpath_variation1/home/tests/link/readlink_realpath_variation1.tmp";
21mkdir("$name_prefix/readlink_realpath_variation1/home/tests/link/", 0777, true);
22
23echo "\n*** Testing readlink() and realpath() with linkname stored inside a object ***\n";
24// create a temp file
25$file_handle = fopen($filename, "w");
26fclose($file_handle);
27
28// creating object with members as linkname
29class object_temp {
30  public $linkname;
31  function __construct($link) {
32    $this->linkname = $link;
33  }
34}
35$obj1 = new object_temp("$name_prefix/readlink_realpath_variation1/../././readlink_realpath_variation1/home/readlink_realpath_variation1_link.tmp");
36$obj2 = new object_temp("$name_prefix/readlink_realpath_variation1/home/../..///readlink_realpath_variation1_link.tmp");
37
38echo "\n-- Testing readlink() and realpath() with softlink, linkname stored inside an object --\n";
39// creating the links
40var_dump( symlink($filename, $obj1->linkname) );
41var_dump( readlink($obj1->linkname) );
42var_dump( realpath($obj1->linkname) );
43var_dump( symlink($filename, $obj2->linkname) );
44var_dump( readlink($obj2->linkname) );
45var_dump( realpath($obj2->linkname) );
46
47// deleting the link
48unlink($obj1->linkname);
49unlink($obj2->linkname);
50
51echo "\n-- Testing readlink() and realpath() with hardlink, linkname stored inside an object --\n";
52// creating hard links
53var_dump( link($filename, $obj1->linkname) );
54var_dump( readlink($obj1->linkname) );   // invalid because readlink doesn't work with hardlink
55var_dump( realpath($obj1->linkname) );
56var_dump( link($filename, $obj2->linkname) );
57var_dump( readlink($obj2->linkname) );   // invalid because readlink doesn't work with hardlink
58var_dump( realpath($obj2->linkname) );
59
60// delete the links
61unlink($obj1->linkname);
62unlink($obj2->linkname);
63
64echo "Done\n";
65?>
66--CLEAN--
67<?php
68$name_prefix = dirname(__FILE__)."/readlink_realpath_variation1";
69unlink("$name_prefix/home/tests/link/readlink_realpath_variation1.tmp");
70rmdir("$name_prefix/home/tests/link/");
71rmdir("$name_prefix/home/tests/");
72rmdir("$name_prefix/home/");
73rmdir("$name_prefix/");
74?>
75--EXPECTF--
76*** Testing readlink() and realpath() : usage variations ***
77
78*** Testing readlink() and realpath() with linkname stored inside a object ***
79
80-- Testing readlink() and realpath() with softlink, linkname stored inside an object --
81bool(true)
82string(%d) "%s/readlink_realpath_variation1/home/tests/link/readlink_realpath_variation1.tmp"
83string(%d) "%s/readlink_realpath_variation1/home/tests/link/readlink_realpath_variation1.tmp"
84bool(true)
85string(%d) "%s/readlink_realpath_variation1/home/tests/link/readlink_realpath_variation1.tmp"
86string(%d) "%s/readlink_realpath_variation1/home/tests/link/readlink_realpath_variation1.tmp"
87
88-- Testing readlink() and realpath() with hardlink, linkname stored inside an object --
89bool(true)
90
91Warning: readlink(): Invalid argument in %s on line %d
92bool(false)
93string(%d) "%s/readlink_realpath_variation1/home/readlink_realpath_variation1_link.tmp"
94bool(true)
95
96Warning: readlink(): Invalid argument in %s on line %d
97bool(false)
98string(%d) "%s/readlink_realpath_variation1_link.tmp"
99Done
100