Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/php/io/File.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function setURI($uri) {
);
$this->path= substr($uri, 0, $p);
$this->filename= ltrim(substr($uri, $p), '/'.DIRECTORY_SEPARATOR);
$this->extension= (false === ($pe= strrpos($this->filename, '.', $s))) ? null : substr($this->filename, $pe+ 1);
$this->extension= (false === ($pe= strrpos($this->filename, '.'))) ? null : substr($this->filename, $pe + 1);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/main/php/io/streams/Streams.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function stream_eof() {
* @return resource
*/
public static function readableFd(InputStream $s) {
$hash= spl_object_hash($s);
$hash= spl_object_id($s);
self::$streams[$hash]= $s;
return fopen('iostrr://'.$hash, 'rb');
}
Expand All @@ -91,7 +91,7 @@ public static function readableFd(InputStream $s) {
* @return string
*/
public static function readableUri(InputStream $s) {
$hash= spl_object_hash($s);
$hash= spl_object_id($s);
self::$streams[$hash]= $s;
return 'iostrr://'.$hash;
}
Expand All @@ -103,7 +103,7 @@ public static function readableUri(InputStream $s) {
* @return resource
*/
public static function writeableFd(OutputStream $s) {
$hash= spl_object_hash($s);
$hash= spl_object_id($s);
self::$streams[$hash]= $s;
return fopen('iostrw://'.$hash, 'wb');
}
Expand All @@ -115,7 +115,7 @@ public static function writeableFd(OutputStream $s) {
* @return resource
*/
public static function writeableUri(OutputStream $s) {
$hash= spl_object_hash($s);
$hash= spl_object_id($s);
self::$streams[$hash]= $s;
return 'iostrw://'.$hash;
}
Expand Down
1 change: 0 additions & 1 deletion src/main/php/lang/Value.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function compareTo($cmp);
/**
* Calculates a hashcode and makes this value useable in e.g. collections.
*
* @see php://spl_object_hash
* @return string
*/
public function hashCode();
Expand Down
6 changes: 3 additions & 3 deletions src/main/php/util/Objects.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static function stringOf($val, $indent= ''): string {
}
return '<function('.substr($sig, 2).')>';
} else if (is_object($val)) {
$hash= spl_object_hash($val);
$hash= spl_object_id($val);
if (isset($protect[$hash])) return '->{:recursion:}';
$protect[$hash]= true;
$r= nameof($val)." {\n";
Expand All @@ -126,15 +126,15 @@ public static function hashOf($val): string {
} else if ($val instanceof Value) {
return $val->hashCode();
} else if ($val instanceof \Closure) {
return spl_object_hash($val);
return spl_object_id($val);
} else if (is_array($val)) {
$s= '';
foreach ($val as $key => $value) {
$s.= '|'.$key.':'.self::hashOf($value);
}
return $s;
} else {
return is_object($val) ? spl_object_hash($val) : serialize($val);
return is_object($val) ? spl_object_id($val) : serialize($val);
}
}
}
10 changes: 5 additions & 5 deletions src/test/php/util/unittest/ObjectsTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public function arrays() {
[[1, 2, 3], '|0:i:1;|1:i:2;|2:i:3;'],
[[null, null], '|0:N;|1:N;'],
[[['Nested'], ['Array']], '|0:|0:s:6:"Nested";|1:|0:s:5:"Array";'],
[[self::$func], '|0:'.spl_object_hash(self::$func)]
[[self::$func], '|0:'.spl_object_id(self::$func)]
];
}

/** @return var[][] */
public function maps() {
return [
[['one' => 'two'], '|one:s:3:"two";'],
[['func' => self::$func], '|func:'.spl_object_hash(self::$func)]
[['func' => self::$func], '|func:'.spl_object_id(self::$func)]
];
}

Expand Down Expand Up @@ -383,12 +383,12 @@ public function hashOf_calls_hashCode_on_objects($val) {
}

#[Test, Values(from: 'natives')]
public function hashOf_calls_spl_object_hash_on_natives($val) {
Assert::equals(spl_object_hash($val), Objects::hashOf($val));
public function hashOf_calls_spl_object_id_on_natives($val) {
Assert::equals((string)spl_object_id($val), Objects::hashOf($val));
}

#[Test]
public function function_hash() {
Assert::equals(spl_object_hash(self::$func), Objects::hashOf(self::$func));
Assert::equals((string)spl_object_id(self::$func), Objects::hashOf(self::$func));
}
}
Loading