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