Skip to content

Commit

Permalink
removed PHP 7 stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 6, 2023
1 parent 82ee9b6 commit de7712e
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/Tracy/BlueScreen/BlueScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct()
? [$m[1] . '/tracy', $m[1] . '/nette', $m[1] . '/latte']
: [dirname(__DIR__)];
$this->fileGenerators[] = [self::class, 'generateNewPhpFileContents'];
$this->fibers = PHP_VERSION_ID < 80000 ? new \SplObjectStorage : new \WeakMap;
$this->fibers = new \WeakMap;
}


Expand Down
4 changes: 0 additions & 4 deletions src/Tracy/Debugger/Debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,6 @@ public static function errorHandler(
self::errorHandler($error['type'], $error['message'], $error['file'], $error['line']);
}

if ($context) {
$context = (array) (object) $context; // workaround for PHP bug #80234
}

if ($severity === E_RECOVERABLE_ERROR || $severity === E_USER_ERROR) {
if (Helpers::findTrace(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), '*::__toString')) { // workaround for PHP < 7.4
$previous = isset($context['e']) && $context['e'] instanceof \Throwable
Expand Down
29 changes: 5 additions & 24 deletions src/Tracy/Dumper/Describer.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,35 +316,16 @@ private static function hideValue($var): string

public function getReferenceId($arr, $key): ?int
{
if (PHP_VERSION_ID >= 70400) {
if ((!$rr = \ReflectionReference::fromArrayElement($arr, $key))) {
return null;
}

$tmp = &$this->references[$rr->getId()];
if ($tmp === null) {
return $tmp = count($this->references);
}

return $tmp;
}

$uniq = new \stdClass;
$copy = $arr;
$orig = $copy[$key];
$copy[$key] = $uniq;
if ($arr[$key] !== $uniq) {
if ((!$rr = \ReflectionReference::fromArrayElement($arr, $key))) {
return null;
}

$res = array_search($uniq, $this->references, true);
$copy[$key] = $orig;
if ($res === false) {
$this->references[] = &$arr[$key];
return count($this->references);
$tmp = &$this->references[$rr->getId()];
if ($tmp === null) {
return $tmp = count($this->references);
}

return $res + 1;
return $tmp;
}


Expand Down
3 changes: 1 addition & 2 deletions src/Tracy/Dumper/Exposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ final class Exposer
{
public static function exposeObject(object $obj, Value $value, Describer $describer): void
{
$tmp = (array) $obj;
$values = $tmp; // bug #79477, PHP < 7.4.6
$values = (array) $obj;
$props = self::getProperties(get_class($obj));

foreach (array_diff_key($values, $props) as $k => $v) {
Expand Down
19 changes: 8 additions & 11 deletions tests/Tracy/Dumper.toHtml().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,24 @@ XX
, Dumper::toHtml($obj));


if (PHP_VERSION_ID >= 70400) {
require __DIR__ . '/fixtures/DumpClass.74.php';

Assert::match(<<<'XX'
// PHP 7.4 features
Assert::match(<<<'XX'
<pre class="tracy-dump tracy-light"
><span class="tracy-toggle"><span class="tracy-dump-object">Test74</span> <span class="tracy-dump-hash">#%d%</span></span>
<div><span class="tracy-dump-indent"> </span><span class="tracy-dump-public">x</span>: <span class="tracy-dump-number">1</span>
<span class="tracy-dump-indent"> </span><span class="tracy-dump-private" title="declared in Test74">y</span>: <span class="tracy-dump-virtual">unset</span>
<span class="tracy-dump-indent"> </span><span class="tracy-dump-protected">z</span>: <span class="tracy-dump-virtual">unset</span>
</div></pre>
XX
, Dumper::toHtml(new Test74));
, Dumper::toHtml(new Test74));


$obj = new Child74;
$obj->new = 7;
unset($obj->unset1, $obj->unset2);
$obj = new Child74;
$obj->new = 7;
unset($obj->unset1, $obj->unset2);


Assert::match(<<<'XX'
Assert::match(<<<'XX'
<pre class="tracy-dump tracy-light"
><span class="tracy-toggle"><span class="tracy-dump-object">Child74</span> <span class="tracy-dump-hash">#%d%</span></span>
<div><span class="tracy-dump-indent"> </span><span class="tracy-dump-dynamic">new</span>: <span class="tracy-dump-number">7</span>
Expand All @@ -171,5 +169,4 @@ XX
<span class="tracy-dump-indent"> </span><span class="tracy-dump-private" title="declared in Test74">y</span>: <span class="tracy-dump-virtual">unset</span>
</div></pre>
XX
, Dumper::toHtml($obj));
}
, Dumper::toHtml($obj));
17 changes: 7 additions & 10 deletions tests/Tracy/Dumper.toText().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,22 @@ XX
, Dumper::toText($obj));


if (PHP_VERSION_ID >= 70400) {
require __DIR__ . '/fixtures/DumpClass.74.php';

Assert::match(<<<'XX'
// PHP 7.4 features
Assert::match(<<<'XX'
Test74 #%d%
x: 1
y: unset
z: unset
XX
, Dumper::toText(new Test74));
, Dumper::toText(new Test74));


$obj = new Child74;
$obj->new = 7;
unset($obj->unset1, $obj->unset2);
$obj = new Child74;
$obj->new = 7;
unset($obj->unset1, $obj->unset2);


Assert::match(<<<'XX'
Assert::match(<<<'XX'
Child74 #%d%
new: 7
x: 2
Expand All @@ -162,4 +160,3 @@ Child74 #%d%
y: unset
XX
, Dumper::toText($obj));
}
21 changes: 0 additions & 21 deletions tests/Tracy/fixtures/DumpClass.74.php

This file was deleted.

18 changes: 18 additions & 0 deletions tests/Tracy/fixtures/DumpClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,21 @@ class Child extends Test
class GrandChild extends Child
{
}

#[\AllowDynamicProperties]
class Test74
{
public int $x = 1;
private int $y;
protected int $z;
}

class Child74 extends Test74
{
public int $x = 2;
private int $y;
protected int $z;

public $unset1;
public int $unset2 = 1;
}

0 comments on commit de7712e

Please sign in to comment.