Ref/uopz-Phpdoc专题
uopz_add_function
Adds non-existent function or method
说明
bool <span
class="methodname">uopz_add_function ( <span
class="methodparam">string $function
, Closure
$handler [, <span
class="type">int &$flags =
ZEND_ACC_PUBLIC ] )
bool <span
class="methodname">uopz_add_function ( <span
class="methodparam">string $class ,
string
$function , <span
class="type">Closure $handler [, <span
class="methodparam">int &$flags<span
class="initializer"> = ZEND_ACC_PUBLIC [, <span
class="methodparam">int &$all<span
class="initializer"> = true ]] )
Adds a non-existent function or method.
参数
class
The name of the class.
function
The name of the function or method.
handler
The Closure that defines the new function
or method.
flags
Flags to set for the new function or method.
all
Whether all classes that descend from class will also be affected.
返回值
成功时返回 true, 或者在失败时返回 false。
错误/异常
uopz_add_function throws a <span class="classname">RuntimeException if the function or method to add already exists.
范例
示例 #1 Basic uopz_add_function Usage
<?php
uopz_add_function('foo', function () {echo 'bar';});
foo();
?>
以上例程会输出:
bar
参见
- uopz_del_function
- uopz_set_return
uopz_allow_exit
Allows control over disabled exit opcode
说明
void <span
class="methodname">uopz_allow_exit ( <span
class="methodparam">bool $allow )
By default uopz disables the exit opcode, so <span class="function">exit calls are practically ignored. <span class="function">uopz_allow_exit allows to control this behavior.
参数
allow
Whether to allow the execution of exit opcodes or not.
返回值
没有返回值。
范例
示例 #1 uopz_allow_exit example
<?php
exit(1);
echo 1;
uopz_allow_exit(true);
exit(2);
echo 2;
?>
以上例程会输出:
1
注释
Caution
OPcache optimizes away dead code after unconditional exit.
参见
- uopz_get_exit_status
uopz_backup
Backup a function
Warning
This function has been REMOVED in PECL uopz 5.0.0.
说明
void <span
class="methodname">uopz_backup ( <span
class="type">string $function )
void <span
class="methodname">uopz_backup ( <span
class="type">string $class , <span
class="methodparam">string $function
)
Backup a function at runtime, to be restored on shutdown
参数
class
The name of the class containing the function to backup
function
The name of the function
返回值
范例
示例 #1 uopz_backup example
<?php
uopz_backup("fgets");
uopz_function("fgets", function(){
return true;
});
var_dump(fgets());
?>
以上例程会输出:
bool(true)
uopz_compose
Compose a class
Warning
This function has been REMOVED in PECL uopz 5.0.0.
说明
void <span
class="methodname">uopz_compose ( <span
class="methodparam">string $name ,
array
$classes [, <span
class="type">array $methods [, <span
class="methodparam">array $properties
[, int
$flags ]]] )
Creates a new class of the given name that implements, extends, or uses all of the provided classes
参数
name
A legal class name
classes
An array of class, interface and trait names
methods
An associative array of methods, values are either closures or
[modifiers => closure]
properties
An associative array of properties, keys are names, values are modifiers
flags
Entry type, by default ZEND_ACC_CLASS
返回值
范例
示例 #1 uopz_compose example
<?php
class myClass {}
trait myTrait {}
interface myInterface {}
uopz_compose(
Composed::class, [
myClass::class,
myTrait::class,
myInterface::class
], [
"__construct" => function() {
/* ... */
}
]);
var_dump(
class_uses(Composed::class),
class_parents(Composed::class),
class_implements(Composed::class));
?>
以上例程会输出:
array(1) {
["myTrait"]=>
string(7) "myTrait"
}
array(1) {
["myClass"]=>
string(7) "myClass"
}
array(1) {
["myInterface"]=>
string(11) "myInterface"
}
uopz_copy
Copy a function
Warning
This function has been REMOVED in PECL uopz 5.0.0.
说明
Closure <span
class="methodname">uopz_copy ( <span
class="type">string $function )
Closure <span
class="methodname">uopz_copy ( <span
class="type">string $class , <span
class="methodparam">string $function
)
Copy a function by name
参数
class
The name of the class containing the function to copy
function
The name of the function
返回值
A Closure for the specified function
范例
示例 #1 uopz_copy example
<?php
$strtotime = uopz_copy('strtotime');
uopz_function("strtotime", function($arg1, $arg2) use($strtotime) {
/* can call original strtotime from here */
var_dump($arg1);
});
var_dump(strtotime('dummy'));
?>
以上例程会输出:
string(5) "dummy"
uopz_del_function
Deletes previously added function or method
说明
bool <span
class="methodname">uopz_del_function ( <span
class="methodparam">string $function
)
bool <span
class="methodname">uopz_del_function ( <span
class="methodparam">string $class ,
string
$function [, <span
class="type">int &$all =
true ] )
Deletes a previously added function or method.
参数
class
The name of the class.
function
The name of the function or method.
all
Whether all classes that descend from class will also be affected.
返回值
成功时返回 true, 或者在失败时返回 false。
错误/异常
uopz_del_function throws a <span class="classname">RuntimeException if the function or method to delete has not been added by <span class="function">uopz_add_function.
范例
示例 #1 Basic uopz_del_function Usage
<?php
uopz_add_function('foo', function () {echo 'bar';});
var_dump(function_exists('foo'));
uopz_del_function('foo');
var_dump(function_exists('foo'));
?>
以上例程会输出:
bool(true)
bool(false)
参见
- uopz_add_function
- uopz_unset_return
uopz_delete
Delete a function
Warning
This function has been REMOVED in PECL uopz 5.0.0.
说明
void <span
class="methodname">uopz_delete ( <span
class="type">string $function )
void <span
class="methodname">uopz_delete ( <span
class="type">string $class , <span
class="methodparam">string $function
)
Deletes a function or method
参数
class
function
返回值
范例
示例 #1 uopz_delete example
<?php
uopz_delete("strlen");
echo strlen("Hello World");
?>
以上例程的输出类似于:
PHP Fatal error: Call to undefined function strlen() in /path/to/script.php on line 4
示例 #2 uopz_delete class example
<?php
class My {
public static function strlen($arg) {
return strlen($arg);
}
}
uopz_delete(My::class, "strlen");
echo My::strlen("Hello World");
?>
以上例程的输出类似于:
PHP Fatal error: Call to undefined method My::strlen() in /path/to/script.php on line 10
uopz_extend
Extend a class at runtime
说明
bool <span
class="methodname">uopz_extend ( <span
class="type">string $class , <span
class="methodparam">string $parent )
Makes class extend parent
参数
class
The name of the class to extend
parent
The name of the class to inherit
返回值
成功时返回 true, 或者在失败时返回 false。
错误/异常
As of PHP 7.4.0, uopz_extends throws a
RuntimeException, if
OPcache is enabled, and
the class entry of either class or parent (if it is a trait) is
immutable.
范例
示例 #1 uopz_extend example
<?php
class A {}
class B {}
uopz_extend(A::class, B::class);
var_dump(class_parents(A::class));
?>
以上例程会输出:
array(1) {
["B"]=>
string(1) "B"
}
uopz_flags
Get or set flags on function or class
说明
int <span
class="methodname">uopz_flags ( <span
class="type">string $function [, <span
class="methodparam">int $flags<span
class="initializer"> = PHP_INT_MAX ] )
int <span
class="methodname">uopz_flags ( <span
class="type">string $class , <span
class="methodparam">string $function
[, int
$flags = PHP_INT_MAX ] )
Get or set the flags on a class or function entry at runtime
参数
class
The name of a class
function
The name of the function. If class is given and an empty string is
passed as function, uopz_flags gets or
sets the flags of the class entry.
flags
A valid set of ZEND_ACC_ flags. If omitted, <span
class="function">uopz_flags acts as getter.
返回值
If setting, returns old flags, else returns flags
错误/异常
As of PHP 7.4.0, if the parameter flags is passed, <span
class="function">uopz_flags throws a <span
class="classname">RuntimeException, if
OPcache is enabled, and
the class entry of class or the function entry of function is
immutable.
更新日志
| 版本 | 说明 |
|---|---|
| PECL uopz 5.0.0 | The flags parameter is now optional. Formerly, ZEND_ACC_FETCH had to be passed to use uopz_flags as getter. |
范例
示例 #1 uopz_flags example
<?php
class Test {
public function method() {
return __CLASS__;
}
}
$flags = uopz_flags("Test", "method");
var_dump((bool) (uopz_flags("Test", "method") & ZEND_ACC_PRIVATE));
var_dump((bool) (uopz_flags("Test", "method") & ZEND_ACC_STATIC));
var_dump(uopz_flags("Test", "method", $flags|ZEND_ACC_STATIC|ZEND_ACC_PRIVATE));
var_dump((bool) (uopz_flags("Test", "method") & ZEND_ACC_PRIVATE));
var_dump((bool) (uopz_flags("Test", "method") & ZEND_ACC_STATIC));
?>
以上例程会输出:
bool(false)
bool(false)
int(1234567890)
bool(true)
bool(true)
示例 #2 "Unfinalize" a Class
<?php
final class MyClass
{
}
$flags = uopz_flags(MyClass::class, '');
uopz_flags(MyClass::class, '', $flags & ~ZEND_ACC_FINAL);
var_dump((new ReflectionClass(MyClass::class)->isFinal());
?>
以上例程会输出:
bool(false)
uopz_function
Creates a function at runtime
Warning
This function has been REMOVED in PECL uopz 5.0.0.
说明
void <span
class="methodname">uopz_function ( <span
class="methodparam">string $function
, Closure
$handler [, <span
class="type">int $modifiers ] )
void <span
class="methodname">uopz_function ( <span
class="methodparam">string $class ,
string
$function , <span
class="type">Closure $handler [, <span
class="methodparam">int $modifiers ]
)
Creates a function at runtime
参数
class
The name of the class to receive the new function
function
The name of the function
handler
The Closure for the function
modifiers
The modifiers for the function, by default copied or ZEND_ACC_PUBLIC
返回值
范例
示例 #1 uopz_function example
<?php
uopz_function("my_strlen", function($arg) {
return strlen($arg);
});
echo my_strlen("Hello World");
?>
以上例程会输出:
11
示例 #2 uopz_function class example
<?php
class My {}
uopz_function(My::class, "strlen", function($arg) {
return strlen($arg);
}, ZEND_ACC_STATIC);
echo My::strlen("Hello World");
?>
以上例程会输出:
11
uopz_get_exit_status
Retrieve the last set exit status
说明
mixed <span class="methodname">uopz_get_exit_status ( <span class="methodparam">void )
Retrieves the last set exit status, i.e. the value passed to <span class="function">exit.
参数
此函数没有参数。
返回值
This function returns the last exit status, or null if <span
class="function">exit has not been called.
范例
示例 #1 uopz_get_exit_status example
<?php
exit(123);
echo uopz_get_exit_status();?>
以上例程会输出:
123
注释
Caution
OPcache optimizes away dead code after unconditional exit.
参见
- uopz_allow_exit
uopz_get_hook
Gets previously set hook on function or method
说明
Closure <span
class="methodname">uopz_get_hook ( <span
class="methodparam">string $function
)
Closure <span
class="methodname">uopz_get_hook ( <span
class="methodparam">string $class ,
string
$function )
Gets the previously set hook on a function or method.
参数
class
The name of the class.
function
The name of the function or method.
返回值
Returns the previously set hook on a function or method, or null
if no hook has been set.
范例
示例 #1 Basic uopz_get_hook Usage
<?php
function foo() {
echo 'foo';
}
uopz_set_hook('foo', function () {echo 'bar';});
var_dump(uopz_get_hook('foo'));
?>
以上例程的输出类似于:
object(Closure)#2 (0) {
}
参见
- uopz_set_hook
- uopz_unset_hook
uopz_get_mock
Get the current mock for a class
说明
mixed <span
class="methodname">uopz_get_mock ( <span
class="methodparam">string $class )
Returns the current mock for class.
参数
class
The name of the mocked class.
返回值
Either a string containing the name of the mock, or an object, or
null if no mock has been set.
范例
示例 #1 uopz_get_mock example
<?php
class A {
public static function who() {
echo "A";
}
}
class mockA {
public static function who() {
echo "mockA";
}
}
uopz_set_mock(A::class, mockA::class);
echo uopz_get_mock(A::class);
?>
以上例程会输出:
mockA
参见
- uopz_set_mock
- uopz_unset_mock
uopz_get_property
Gets value of class or instance property
说明
mixed <span
class="methodname">uopz_get_property ( <span
class="methodparam">string $class ,
string
$property )
mixed <span
class="methodname">uopz_get_property ( <span
class="methodparam">object $instance
, string
$property )
Gets the value of a static class property, if class is given, or the
value of an instance property, if instance is given.
参数
class
The name of the class.
instance
The object instance.
property
The name of the property.
返回值
Returns the value of the class or instance property, or null if
the property is not defined.
范例
示例 #1 Basic uopz_get_property Usage
<?php
class Foo {
private static $staticBar = 10;
private $bar = 100;
}
$foo = new Foo;
var_dump(uopz_get_property('Foo', 'staticBar'));
var_dump(uopz_get_property($foo, 'bar'));
?>
以上例程的输出类似于:
int(10)
int(100)
参见
- uopz_set_property
uopz_get_return
Gets a previous set return value for a function
说明
mixed <span
class="methodname">uopz_get_return ( <span
class="methodparam">string $function
)
mixed <span
class="methodname">uopz_get_return ( <span
class="methodparam">string $class ,
string
$function )
Gets the return value of the function previously set by <span
class="methodname">uopz_set_return.
参数
class
The name of the class containing the function
function
The name of the function
返回值
The return value or Closure previously set.
范例
示例 #1 uopz_get_return example
<?php
uopz_set_return("strlen", 42);
echo uopz_get_return("strlen");
?>
以上例程会输出:
42
uopz_get_static
Gets the static variables from function or method scope
说明
array <span
class="methodname">uopz_get_static ( <span
class="methodparam">string $class ,
string
$function )
array <span
class="methodname">uopz_get_static ( <span
class="methodparam">string $function
)
Gets the static variables from function or method scope.
参数
class
The name of the class.
function
The name of the function or method.
返回值
Returns an associative array of variable names
mapped to their current values on success, or null if the function
or method does not exist.
范例
示例 #1 Basic uopz_get_static Usage
<?php
function foo() {
static $bar = 'baz';
}
var_dump(uopz_get_static('foo'));
?>
以上例程会输出:
array(1) {
["bar"]=>
string(3) "baz"
}
参见
- uopz_set_static
uopz_implement
Implements an interface at runtime
说明
bool <span
class="methodname">uopz_implement ( <span
class="methodparam">string $class ,
string
$interface )
Makes class implement interface
参数
class
interface
返回值
成功时返回 true, 或者在失败时返回 false。
错误/异常
As of PHP 7.4.0, uopz_implements throws a
RuntimeException, if
OPcache is enabled, and
the class entry of class is immutable.
范例
示例 #1 uopz_implement example
<?php
interface myInterface {}
class myClass {}
uopz_implement(myClass::class, myInterface::class);
var_dump(class_implements(myClass::class));
?>
以上例程会输出:
array(1) {
["myInterface"]=>
string(11) "myInterface"
}
uopz_overload
Overload a VM opcode
Warning
This function has been REMOVED in PECL uopz 5.0.0.
说明
void <span
class="methodname">uopz_overload ( <span
class="methodparam">int $opcode ,
Callable
$callable )
Overloads the specified opcode with the user defined function
参数
opcode
A valid opcode, see constants for details of supported codes
callable
返回值
范例
示例 #1 uopz_overload example
<?php
uopz_overload(ZEND_EXIT, function(){});
exit();
echo "Hello World";
?>
以上例程会输出:
Hello World
uopz_redefine
Redefine a constant
说明
bool <span
class="methodname">uopz_redefine ( <span
class="methodparam">string $constant
, mixed
$value )
bool <span
class="methodname">uopz_redefine ( <span
class="methodparam">string $class ,
string
$constant , <span
class="type">mixed $value )
Redefines the given constant as value
参数
class
The name of the class containing the constant
constant
The name of the constant
value
The new value for the constant, must be a valid type for a constant
variable
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 uopz_redefine example
<?php
define("MY", 100);
uopz_redefine("MY", 1000);
echo MY;
?>
以上例程会输出:
1000
uopz_rename
Rename a function at runtime
Warning
This function has been REMOVED in PECL uopz 5.0.0.
说明
void <span
class="methodname">uopz_rename ( <span
class="type">string $function , <span
class="methodparam">string $rename )
void <span
class="methodname">uopz_rename ( <span
class="type">string $class , <span
class="methodparam">string $function
, string
$rename )
Renames function to rename
Note:
If both functions exist, this effectively swaps their names
参数
class
The name of the class containing the function
function
The name of an existing function
rename
The new name for the function
返回值
范例
示例 #1 uopz_rename example
<?php
uopz_rename("strlen", "original_strlen");
echo original_strlen("Hello World");
?>
以上例程会输出:
11
示例 #2 uopz_rename class example
<?php
class My {
public function strlen($arg) {
return strlen($arg);
}
}
uopz_rename(My::class, "strlen", "original_strlen");
echo My::original_strlen("Hello World");
?>
以上例程会输出:
11
uopz_restore
Restore a previously backed up function
Warning
This function has been REMOVED in PECL uopz 5.0.0.
说明
void <span
class="methodname">uopz_restore ( <span
class="methodparam">string $function
)
void <span
class="methodname">uopz_restore ( <span
class="methodparam">string $class ,
string
$function )
Restore a previously backed up function
参数
class
The name of the class containing the function to restore
function
The name of the function
返回值
范例
示例 #1 uopz_restore example
<?php
uopz_backup("fgets");
uopz_function("fgets", function(){
return true;
});
var_dump(fgets());
uopz_restore('fgets');
fgets();
?>
以上例程的输出类似于:
Warning: fgets() expects at least 1 parameter, 0 given in /path/to/script.php on line 8
uopz_set_hook
Sets hook to execute when entering a function or method
说明
bool <span
class="methodname">uopz_set_hook ( <span
class="methodparam">string $function
, Closure
$hook )
bool <span
class="methodname">uopz_set_hook ( <span
class="methodparam">string $class ,
string
$function , <span
class="type">Closure $hook )
Sets a hook to execute when entering a function or method.
参数
class
The name of the class.
function
The name of the function or method.
hook
A closure to execute when entering the function or method.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 Basic uopz_set_hook Usage
<?php
function foo() {
echo 'foo';
}
uopz_set_hook('foo', function () {echo 'bar';});
foo();
?>
以上例程会输出:
barfoo
参见
- uopz_get_hook
- uopz_unset_hook
uopz_set_mock
Use mock instead of class for new objects
说明
void <span
class="methodname">uopz_set_mock ( <span
class="methodparam">string $class ,
mixed $mock
)
If mock is a string containing the name of a class then it will be
instantiated instead of class. mock can also be an object.
Note:
Only dynamic access to properties and methods will use the
mockobject. Static access still uses the originalclass. See example below.
参数
class
The name of the class to be mocked.
mock
The mock to use in the form of a string containing the name of the class
to use or an object. If a string is passed, it has to be the fully
qualified class name. It is recommended to use the ::class magic
constant in this case.
更新日志
| 版本 | 说明 |
|---|---|
| uopz 6.0.0 | Mocking static members is no longer supported by this function. uopz_redefine and uopz_set_return, or Componere can be used instead. |
范例
示例 #1 uopz_set_mock example
<?php
class A {
public function who() {
echo "A";
}
}
class mockA {
public function who() {
echo "mockA";
}
}
uopz_set_mock(A::class, mockA::class);
(new A)->who();
?>
以上例程会输出:
mockA
示例 #2 uopz_set_mock example
<?php
class A {
public function who() {
echo "A";
}
}
uopz_set_mock(A::class, new class {
public function who() {
echo "mockA";
}
});
(new A)->who();
?>
以上例程会输出:
mockA
示例 #3 uopz_set_mock and static members
As of uopz 6.0.0 mocking static members is no longer supported.
<?php
class A {
const CON = 'A';
public static function who() {
echo "A";
}
}
uopz_set_mock(A::class, new class {
const CON = 'mockA';
public static function who() {
echo "mockA";
}
});
echo A::CON, PHP_EOL;
A::who();
?>
以上例程会输出:
A
A
Output of the above example in uopz 5:
mockA
mockA
参见
- uopz_get_mock
- uopz_unset_mock
uopz_set_property
Sets value of existing class or instance property
说明
void <span
class="methodname">uopz_set_property ( <span
class="methodparam">string $class ,
string
$property , <span
class="type">mixed $value )
void <span
class="methodname">uopz_set_property ( <span
class="methodparam">object $instance
, string
$property , <span
class="type">mixed $value )
Sets the value of an existing static class property, if class is
given, or the value of an instance property (regardless whether the
instance property already exists), if instance is given.
参数
class
The name of the class.
instance
The object instance.
property
The name of the property.
value
The value to assign to the property.
返回值
没有返回值。
范例
示例 #1 Basic uopz_set_property Usage
<?php
class Foo {
private static $staticBar;
private $bar;
public static function testStaticBar() {
return self::$staticBar;
}
public function testBar() {
return $this->bar;
}
}
$foo = new Foo;
uopz_set_property('Foo', 'staticBar', 10);
uopz_set_property($foo, 'bar', 100);
var_dump(Foo::testStaticBar());
var_dump($foo->testBar());
?>
以上例程会输出:
int(10)
参见
- uopz_get_property
uopz_set_return
Provide a return value for an existing function
说明
bool <span
class="methodname">uopz_set_return ( <span
class="methodparam">string $function
, mixed
$value [, <span
class="type">bool $execute =
false ] )
bool <span
class="methodname">uopz_set_return ( <span
class="methodparam">string $class ,
string
$function , <span
class="type">mixed $value [, <span
class="methodparam">bool $execute<span
class="initializer"> = false ] )
Sets the return value of the function to value. If value is a
Closure and execute is set, the Closure will be executed in place of
the original function. It is possible to call the original function from
the Closure.
Note:
This function replaces uopz_rename.
参数
class
The name of the class containing the function
function
The name of an existing function
value
The value the function should return. If a Closure is provided and the
execute flag is set, the Closure will be executed in place of the
original function.
execute
If true, and a Closure was provided as the value, the Closure will be
executed in place of the original function.
返回值
True if succeeded, false otherwise.
范例
示例 #1 uopz_set_return example
<?php
uopz_set_return("strlen", 42);
echo strlen("Banana");
?>
以上例程会输出:
42
示例 #2 uopz_set_return example
<?php
uopz_set_return("strlen", function($str) { return strlen($str) * 2; }, true );
echo strlen("Banana");
?>
以上例程会输出:
12
示例 #3 uopz_set_return class example
<?php
class My {
public static function strlen($arg) {
return strlen($arg);
}
}
uopz_set_return(My::class, "strlen", function($str) { return strlen($str) * 2; }, true );
echo My::strlen("Banana");
?>
以上例程会输出:
12
uopz_set_static
Sets the static variables in function or method scope
说明
void <span
class="methodname">uopz_set_static ( <span
class="methodparam">string $function
, array
$static )
void <span
class="methodname">uopz_set_static ( <span
class="methodparam">string $class ,
string
$function , <span
class="type">array $static )
Sets the static variables in function or method scope.
参数
class
The name of the class.
function
The name of the function or method.
static
The associative array of variable names mapped
to their values.
返回值
没有返回值。
范例
示例 #1 Basic uopz_set_static Usage
<?php
function foo() {
static $bar = 'baz';
var_dump($bar);
}
uopz_set_static('foo', ['bar' => 'qux']);
foo();
?>
以上例程会输出:
string(3) "qux"
参见
- uopz_get_static
uopz_undefine
Undefine a constant
说明
bool <span
class="methodname">uopz_undefine ( <span
class="methodparam">string $constant
)
bool <span
class="methodname">uopz_undefine ( <span
class="methodparam">string $class ,
string
$constant )
Removes the constant at runtime
参数
class
The name of the class containing constant
constant
The name of an existing constant
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 uopz_undefine example
<?php
define("MY", true);
uopz_undefine("MY");
var_dump(defined("MY"));
?>
以上例程会输出:
bool(false)
uopz_unset_hook
Removes previously set hook on function or method
说明
bool <span
class="methodname">uopz_unset_hook ( <span
class="methodparam">string $function
)
bool <span
class="methodname">uopz_unset_hook ( <span
class="methodparam">string $class ,
string
$function )
Removes the previously set hook on a function or method.
参数
class
The name of the class.
function
The name of the function or method.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 Basic uopz_unset_hook Usage
<?php
function foo() {
echo 'foo';
}
uopz_set_hook('foo', function () {echo 'bar';});
foo();
echo PHP_EOL;
uopz_unset_hook('foo');
foo();
?>
以上例程会输出:
barfoo
foo
参见
- uopz_set_hook
- uopz_get_hook
uopz_unset_mock
Unset previously set mock
说明
void <span
class="methodname">uopz_unset_mock ( <span
class="methodparam">string $class )
Unsets the previously set mock for class.
参数
class
The name of the mocked class.
错误/异常
A RuntimeException is thrown, if no mock
was previously set for class.
范例
示例 #1 uopz_unset_mock example
<?php
class A {
public static function who() {
echo "A";
}
}
class mockA {
public static function who() {
echo "mockA";
}
}
uopz_set_mock(A::class, mockA::class);
uopz_unset_mock(A::class);
A::who();
?>
以上例程会输出:
A
参见
- uopz_set_mock
- uopz_get_mock
uopz_unset_return
Unsets a previously set return value for a function
说明
bool <span
class="methodname">uopz_unset_return ( <span
class="methodparam">string $function
)
bool <span
class="methodname">uopz_unset_return ( <span
class="methodparam">string $class ,
string
$function )
Unsets the return value of the function previously set by <span
class="methodname">uopz_set_return.
参数
class
The name of the class containing the function
function
The name of the function
返回值
True on success
范例
示例 #1 uopz_unset_return example
<?php
uopz_set_return("strlen", 42);
$len = strlen("Banana");
uopz_unset_return("strlen");
echo $len + strlen("Banana");
?>
以上例程会输出:
48
目录
- uopz_add_function — Adds non-existent function or method
- uopz_allow_exit — Allows control over disabled exit opcode
- uopz_backup — Backup a function
- uopz_compose — Compose a class
- uopz_copy — Copy a function
- uopz_del_function — Deletes previously added function or method
- uopz_delete — Delete a function
- uopz_extend — Extend a class at runtime
- uopz_flags — Get or set flags on function or class
- uopz_function — Creates a function at runtime
- uopz_get_exit_status — Retrieve the last set exit status
- uopz_get_hook — Gets previously set hook on function or method
- uopz_get_mock — Get the current mock for a class
- uopz_get_property — Gets value of class or instance property
- uopz_get_return — Gets a previous set return value for a function
- uopz_get_static — Gets the static variables from function or method scope
- uopz_implement — Implements an interface at runtime
- uopz_overload — Overload a VM opcode
- uopz_redefine — Redefine a constant
- uopz_rename — Rename a function at runtime
- uopz_restore — Restore a previously backed up function
- uopz_set_hook — Sets hook to execute when entering a function or method
- uopz_set_mock — Use mock instead of class for new objects
- uopz_set_property — Sets value of existing class or instance property
- uopz_set_return — Provide a return value for an existing function
- uopz_set_static — Sets the static variables in function or method scope
- uopz_undefine — Undefine a constant
- uopz_unset_hook — Removes previously set hook on function or method
- uopz_unset_mock — Unset previously set mock
- uopz_unset_return — Unsets a previously set return value for a function