1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! PHP reference wrapper that explicitly requires pass-by-reference from callers.
use ;
use crateFromZvalMut;
use crateDataType;
use crateZval;
/// A PHP reference (`&$x`) that explicitly requires the caller to pass by
/// reference.
///
/// Use this type in [`#[php_function]`](crate::php_function) signatures when
/// you need to modify the caller's original variable. This is the **only** type
/// that sets PHP's `ZEND_SEND_BY_REF` flag.
///
/// Mutations through `PhpRef` affect the original variable in the caller's
/// scope. The proc macro automatically dereferences the `zend_reference`
/// wrapper before passing the inner value to your function.
///
/// # When to use `PhpRef` vs `Separated`
///
/// | Type | PHP call syntax | Caller's variable modified? |
/// |---|---|---|
/// | [`Separated`](super::Separated) | `foo($x)` or `foo([1,2])` | No |
/// | `PhpRef` | `foo(&$x)` — literals rejected | Yes |
///
/// # Examples
///
/// ```rust,ignore
/// use ext_php_rs::prelude::*;
/// use ext_php_rs::types::PhpRef;
///
/// #[php_function]
/// pub fn increment(mut val: PhpRef) {
/// if let Some(n) = val.long() {
/// val.set_long(n + 1);
/// }
/// }
/// ```
///
/// ```php
/// $x = 5;
/// increment($x); // $x is now 6
/// ```
;