Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Internal types

DST & Owned Type

In Rust, there are many types that appear in pairs, like str / String, OsStr / OsString, CStr / CString.

For example:

  • str: Dynamically sized type, implements !Sized, usually used with reference notation, as &str.
  • String: Ownership type, encapsulates a pointer to a heap memory allocation.

PHPER follows this design, there are the following types:

It seems that there is no need to separate into two types, but ZStr, ZArr, and ZObj are all transparent types. Therefore, the fields of the struct cannot be changed. Separating an ownership struct ZString, ZArray, and ZObject, and then we can change fields of the struct in the future.

Mapping relationship

Here is the mapping of relationships between Rust types and base PHP types.

Rust typePHP type
()null
boolbool
i64long
f64double
ZStr / ZStringstring
ZArr / ZArrayarray
ZObj / ZObjectobject
ZResresource

Why is there no ZResource? Because Resource is a relatively old type, it is generally replaced by Class now, and the role of ZRes is only compatible with old extension resources.