phpval

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package phpval holds PHP's value semantics: how a value converts to a string, an integer or a truth value, how a collection reads back as a list of values or strings, and how two values order under PHP 8's <=> operator.

It exists so the files under stdlib/core can each register their own area without importing one another. Every one of them coerces its arguments, and the coercion has to have exactly one definition: sort() and in_array() disagreeing about what "10" is would be a bug no test names.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(x, y any) int

Compare is PHP 8's comparison operator (<=>), which sort() and rsort() order by. Its rules, in the order they are applied:

arrays          the shorter array is smaller, an array beats any scalar
null vs string  the null becomes "" and the two compare as strings
bool or null    both sides are cast to bool
numbers         two numbers, or a number and a numeric string, or two
                numeric strings, compare numerically, so "9" is less than
                "10", and a list of digits out of explode() sorts the way
                the same list sorts in PHP
anything else   both sides are cast to string and compared bytewise, which
                is where a number meeting a non-numeric string ends up

func Int

func Int(v any) int64

func String

func String(v any) string

func Strings

func Strings(a any) []string

Strings returns a collection's values as strings in order.

func Truthy

func Truthy(v any) bool

func Values

func Values(a any) []any

Values returns a collection's values in order. A []any is returned as is: callers only read it, and the shims that do not (array_splice) copy first.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL