Skip to content

Commit c4668fe

Browse files
committed
feat: add global function remoteStaticCall
1 parent e37b94e commit c4668fe

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver].
66

7+
## v4.3.0
8+
9+
### Added
10+
11+
- Add global function: `remoteStaticCall`
12+
713
## v4.2.0
814

915
### Added

src/Global/base.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,28 @@ function class_uses_recursive($class): array
156156
return array_unique($results);
157157
}
158158
}
159+
160+
161+
if (!function_exists('remoteStaticCall')) {
162+
/**
163+
* Returns result of an object's method if it exists in the object.
164+
*
165+
* @param string|object|null $class
166+
* @param string $method
167+
* @param mixed ...$params
168+
*
169+
* @return mixed
170+
*/
171+
function remoteStaticCall(object|string|null $class, string $method, mixed ...$params): mixed
172+
{
173+
if (!$class) {
174+
return null;
175+
}
176+
177+
if (is_object($class) || (is_string($class) && class_exists($class))) {
178+
return $class::$method(...$params);
179+
}
180+
181+
return null;
182+
}
183+
}

0 commit comments

Comments
 (0)