Person
extends Person
in package
Table of Contents
- GENDER_FEMALE = 'female'
- GENDER_MALE = 'male'
- $femaleNameFormats : mixed
- $firstNameFemale : mixed
- $firstNameFormat : mixed
- $firstNameMale : mixed
- $generator : Generator
- $lastName : mixed
- According to http://baike.baidu.com/view/6109935.htm, these are the top 300 lastnames from the 6th Chinese national census of population, containing 299 single-character surname and 1 double-character surname '欧阳', so you can get random names including double-character surname but not too many.
- $maleNameFormats : mixed
- $titleFemale : mixed
- $titleFormat : mixed
- $titleMale : mixed
- $unique : UniqueGenerator
- __construct() : mixed
- asciify() : string
- Replaces * signs with random numbers and letters and special characters
- bothify() : string
- Replaces hash signs ('#') and question marks ('?') with random numbers and letters An asterisk ('*') is replaced with either a random number or a random letter
- firstName() : string
- firstNameFemale() : string
- firstNameMale() : string
- lastName() : string
- lexify() : string
- Replaces all question mark ('?') occurrences with a random letter
- name() : string
- numberBetween() : int
- Returns a random number between $int1 and $int2 (any order)
- numerify() : string
- Replaces all hash sign ('#') occurrences with a random number Replaces all percentage sign ('%') occurrences with a not null number
- optional() : mixed|null
- Chainable method for making any formatter optional.
- passthrough() : mixed
- Returns the passed value
- randomAscii() : string
- Returns a random ASCII character (excluding accents and special chars)
- randomDigit() : int
- Returns a random number between 0 and 9
- randomDigitNot() : int
- Generates a random digit, which cannot be $except
- randomDigitNotNull() : int
- Returns a random number between 1 and 9
- randomElement() : mixed
- Returns a random element from a passed array
- randomElements() : array<string|int, mixed>
- Returns randomly ordered subsequence of $count elements from a provided array
- randomFloat() : float
- Return a random float number
- randomKey() : int|string|null
- Returns a random key from a passed associative array
- randomLetter() : string
- Returns a random letter from a to z
- randomNumber() : int
- Returns a random integer with 0 to $nbDigits digits.
- regexify() : string
- Transforms a basic regular expression into a random string satisfying the expression.
- shuffle() : array<string|int, mixed>|string
- Returns a shuffled version of the argument.
- shuffleArray() : array<string|int, mixed>
- Returns a shuffled version of the array.
- shuffleString() : string
- Returns a shuffled version of the string.
- title() : string
- titleFemale() : string
- titleMale() : string
- toLower() : string
- Converts string to lowercase.
- toUpper() : string
- Converts string to uppercase.
- unique() : UniqueGenerator
- Chainable method for making any formatter unique.
- valid() : ValidGenerator
- Chainable method for forcing any formatter to return only valid values.
- replaceWildcard() : mixed
Constants
GENDER_FEMALE
public
mixed
GENDER_FEMALE
= 'female'
GENDER_MALE
public
mixed
GENDER_MALE
= 'male'
Properties
$femaleNameFormats
protected
static mixed
$femaleNameFormats
= ['{{lastName}}{{firstNameFemale}}']
$firstNameFemale
protected
static mixed
$firstNameFemale
= ['芳', '娜', '敏', '静', '敏静', '秀英', '丽', '洋', '艳', '娟', '文娟', '君', '文君', '珺', '霞', '明霞', '秀兰', '燕', '芬', '桂芬', '玲', '桂英', '丹', '萍', '华', '红', '玉兰', '桂兰', '英', '梅', '莉', '秀珍', '雪', '依琳', '旭', '宁', '婷', '馨予', '玉珍', '凤英', '晶', '欢', '玉英', '颖', '红梅', '佳', '倩', '琴', '兰英', '云', '洁', '爱华', '淑珍', '春梅', '海燕', '晨', '冬梅', '秀荣', '瑞', '桂珍', '莹', '秀云', '桂荣', '秀梅', '丽娟', '婷婷', '玉华', '琳', '雪梅', '淑兰', '丽丽', '玉', '秀芳', '欣', '淑英', '桂芳', '丽华', '丹丹', '桂香', '淑华', '秀华', '桂芝', '小红', '金凤', '文', '利', '楠', '红霞', '瑜', '桂花', '璐', '凤兰', '腊梅', '瑶', '嘉', '怡', '冰冰', '玉梅', '慧', '婕']
$firstNameFormat
protected
static mixed
$firstNameFormat
= ['{{firstNameMale}}', '{{firstNameFemale}}']
$firstNameMale
protected
static mixed
$firstNameMale
= ['伟', '强', '磊', '洋', '勇', '军', '杰', '涛', '超', '明', '刚', '平', '辉', '鹏', '华', '飞', '鑫', '波', '斌', '宇', '浩', '凯', '健', '俊', '帆', '帅', '旭', '宁', '龙', '林', '欢', '阳', '建华', '亮', '成', '畅', '建', '峰', '建国', '建军', '晨', '瑞', '志强', '兵', '雷', '东', '欣', '博', '彬', '坤', '全安', '荣', '岩', '杨', '文', '利', '楠', '建平', '嘉俊', '晧', '建明', '子安', '新华', '鹏程', '学明', '博涛', '捷', '文彬', '楼', '鹰', '松', '伦', '超', '钟', '瑜', '振国', '洪', '毅', '昱然', '哲', '翔', '翼', '祥', '国庆', '哲彦', '正诚', '正豪', '正平', '正业', '志诚', '志新', '志勇', '志明', '志强', '志文', '致远', '智明', '智勇', '智敏', '智渊']
$generator
protected
Generator
$generator
$lastName
According to http://baike.baidu.com/view/6109935.htm, these are the top 300 lastnames from the 6th Chinese national census of population, containing 299 single-character surname and 1 double-character surname '欧阳', so you can get random names including double-character surname but not too many.
protected
static mixed
$lastName
= ['李', '王', '张', '刘', '陈', '杨', '赵', '黄', '周', '吴', '徐', '孙', '胡', '朱', '高', '林', '何', '郭', '马', '罗', '梁', '宋', '郑', '谢', '韩', '唐', '冯', '于', '董', '萧', '程', '曹', '袁', '邓', '许', '傅', '沉', '曾', '彭', '吕', '苏', '卢', '蒋', '蔡', '贾', '丁', '林', '薛', '叶', '阎', '余', '潘', '杜', '戴', '夏', '钟', '汪', '田', '任', '姜', '范', '方', '石', '姚', '谭', '廖', '邹', '熊', '金', '陆', '郝', '孔', '白', '崔', '康', '毛', '邱', '秦', '江', '史', '顾', '侯', '邵', '孟', '龙', '万', '段', '雷', '钱', '汤', '尹', '黎', '易', '常', '武', '乔', '贺', '赖', '龚', '文', '庞', '樊', '兰', '殷', '施', '陶', '洪', '翟', '安', '颜', '倪', '严', '牛', '温', '芦', '季', '俞', '章', '鲁', '葛', '伍', '韦', '申', '尤', '毕', '聂', '丛', '焦', '向', '柳', '邢', '路', '岳', '齐', '沿', '梅', '莫', '庄', '辛', '管', '祝', '左', '涂', '谷', '祁', '时', '舒', '耿', '牟', '卜', '路', '詹', '关', '苗', '凌', '费', '纪', '靳', '盛', '童', '欧', '甄', '项', '曲', '成', '游', '阳', '裴', '席', '卫', '查', '屈', '鲍', '位', '覃', '霍', '翁', '隋', '植', '甘', '景', '薄', '单', '包', '司', '柏', '宁', '柯', '阮', '桂', '闵', '欧阳', '解', '强', '柴', '华', '车', '冉', '房', '边', '辜', '吉', '饶', '刁', '瞿', '戚', '丘', '古', '米', '池', '滕', '晋', '苑', '邬', '臧', '畅', '宫', '来', '嵺', '苟', '全', '褚', '廉', '简', '娄', '盖', '符', '奚', '木', '穆', '党', '燕', '郎', '邸', '冀', '谈', '姬', '屠', '连', '郜', '晏', '栾', '郁', '商', '蒙', '计', '喻', '揭', '窦', '迟', '宇', '敖', '糜', '鄢', '冷', '卓', '花', '仇', '艾', '蓝', '都', '巩', '稽', '井', '练', '仲', '乐', '虞', '卞', '封', '竺', '冼', '原', '官', '衣', '楚', '佟', '栗', '匡', '宗', '应', '台', '巫', '鞠', '僧', '桑', '荆', '谌', '银', '扬', '明', '沙', '薄', '伏', '岑', '习', '胥', '保', '和', '蔺']
$maleNameFormats
protected
static mixed
$maleNameFormats
= ['{{lastName}}{{firstNameMale}}']
$titleFemale
protected
static mixed
$titleFemale
= ['女士', '小姐', '夫人', '太太', '医生', '老师', '教授', '律师', '经理']
$titleFormat
protected
static mixed
$titleFormat
= ['{{titleMale}}', '{{titleFemale}}']
$titleMale
protected
static mixed
$titleMale
= ['先生', '医生', '老师', '教授', '律师', '经理']
$unique
protected
UniqueGenerator
$unique
Methods
__construct()
public
__construct(Generator $generator) : mixed
Parameters
- $generator : Generator
Return values
mixed —asciify()
Replaces * signs with random numbers and letters and special characters
public
static asciify([string $string = '****' ]) : string
Parameters
- $string : string = '****'
-
String that needs to bet parsed
Tags
Return values
string —bothify()
Replaces hash signs ('#') and question marks ('?') with random numbers and letters An asterisk ('*') is replaced with either a random number or a random letter
public
static bothify([string $string = '## ??' ]) : string
Parameters
- $string : string = '## ??'
-
String that needs to bet parsed
Return values
string —firstName()
public
firstName([string|null $gender = null ]) : string
Parameters
- $gender : string|null = null
-
'male', 'female' or null for any
Tags
Return values
string —firstNameFemale()
public
static firstNameFemale() : string
Return values
string —firstNameMale()
public
static firstNameMale() : string
Return values
string —lastName()
public
lastName() : string
Tags
Return values
string —lexify()
Replaces all question mark ('?') occurrences with a random letter
public
static lexify([string $string = '????' ]) : string
Parameters
- $string : string = '????'
-
String that needs to bet parsed
Return values
string —name()
public
name([string|null $gender = null ]) : string
Parameters
- $gender : string|null = null
-
'male', 'female' or null for any
Tags
Return values
string —numberBetween()
Returns a random number between $int1 and $int2 (any order)
public
static numberBetween(int $int1[, int $int2 = 2147483647 ]) : int
Parameters
- $int1 : int
-
default to 0
- $int2 : int = 2147483647
-
defaults to 32 bit max integer, ie 2147483647
Tags
Return values
int —numerify()
Replaces all hash sign ('#') occurrences with a random number Replaces all percentage sign ('%') occurrences with a not null number
public
static numerify([string $string = '###' ]) : string
Parameters
- $string : string = '###'
-
String that needs to bet parsed
Return values
string —optional()
Chainable method for making any formatter optional.
public
optional([float|int $weight = 0.5 ][, mixed $default = null ]) : mixed|null
Parameters
- $weight : float|int = 0.5
-
Set the probability of receiving a null value. "0" will always return null, "1" will always return the generator. If $weight is an integer value, then the same system works between 0 (always get false) and 100 (always get true).
- $default : mixed = null
Return values
mixed|null —passthrough()
Returns the passed value
public
static passthrough(mixed $value) : mixed
Parameters
- $value : mixed
Return values
mixed —randomAscii()
Returns a random ASCII character (excluding accents and special chars)
public
static randomAscii() : string
Return values
string —randomDigit()
Returns a random number between 0 and 9
public
static randomDigit() : int
Return values
int —randomDigitNot()
Generates a random digit, which cannot be $except
public
static randomDigitNot(int $except) : int
Parameters
- $except : int
Return values
int —randomDigitNotNull()
Returns a random number between 1 and 9
public
static randomDigitNotNull() : int
Return values
int —randomElement()
Returns a random element from a passed array
public
static randomElement([array<string|int, mixed> $array = ['a', 'b', 'c'] ]) : mixed
Parameters
- $array : array<string|int, mixed> = ['a', 'b', 'c']
Return values
mixed —randomElements()
Returns randomly ordered subsequence of $count elements from a provided array
public
static randomElements([array<string|int, mixed> $array = ['a', 'b', 'c'] ][, int $count = 1 ][, bool $allowDuplicates = false ]) : array<string|int, mixed>
Parameters
- $array : array<string|int, mixed> = ['a', 'b', 'c']
-
Array to take elements from. Defaults to a-c
- $count : int = 1
-
Number of elements to take.
- $allowDuplicates : bool = false
-
Allow elements to be picked several times. Defaults to false
Tags
Return values
array<string|int, mixed> —New array with $count elements from $array
randomFloat()
Return a random float number
public
static randomFloat([int $nbMaxDecimals = null ], float|int $min[, float|int $max = null ]) : float
Parameters
- $nbMaxDecimals : int = null
- $min : float|int
- $max : float|int = null
Tags
Return values
float —randomKey()
Returns a random key from a passed associative array
public
static randomKey([array<string|int, mixed> $array = [] ]) : int|string|null
Parameters
- $array : array<string|int, mixed> = []
Return values
int|string|null —randomLetter()
Returns a random letter from a to z
public
static randomLetter() : string
Return values
string —randomNumber()
Returns a random integer with 0 to $nbDigits digits.
public
static randomNumber([int $nbDigits = null ][, bool $strict = false ]) : int
The maximum value returned is mt_getrandmax()
Parameters
- $nbDigits : int = null
-
Defaults to a random number between 1 and 9
- $strict : bool = false
-
Whether the returned number should have exactly $nbDigits
Tags
Return values
int —regexify()
Transforms a basic regular expression into a random string satisfying the expression.
public
static regexify([string $regex = '' ]) : string
Parameters
- $regex : string = ''
-
A regular expression (delimiters are optional)
Tags
Return values
string —shuffle()
Returns a shuffled version of the argument.
public
static shuffle([array<string|int, mixed>|string $arg = '' ]) : array<string|int, mixed>|string
This function accepts either an array, or a string.
Parameters
- $arg : array<string|int, mixed>|string = ''
-
The set to shuffle
Tags
Return values
array<string|int, mixed>|string —The shuffled set
shuffleArray()
Returns a shuffled version of the array.
public
static shuffleArray([array<string|int, mixed> $array = [] ]) : array<string|int, mixed>
This function does not mutate the original array. It uses the Fisher–Yates algorithm, which is unbiased, together with a Mersenne twister random generator. This function is therefore more random than PHP's shuffle() function, and it is seedable.
Parameters
- $array : array<string|int, mixed> = []
-
The set to shuffle
Tags
Return values
array<string|int, mixed> —The shuffled set
shuffleString()
Returns a shuffled version of the string.
public
static shuffleString([string $string = '' ][, string $encoding = 'UTF-8' ]) : string
This function does not mutate the original string. It uses the Fisher–Yates algorithm, which is unbiased, together with a Mersenne twister random generator. This function is therefore more random than PHP's shuffle() function, and it is seedable. Additionally, it is UTF8 safe if the mb extension is available.
Parameters
- $string : string = ''
-
The set to shuffle
- $encoding : string = 'UTF-8'
-
The string encoding (defaults to UTF-8)
Tags
Return values
string —The shuffled set
title()
public
title([string|null $gender = null ]) : string
Parameters
- $gender : string|null = null
-
'male', 'female' or null for any
Tags
Return values
string —titleFemale()
public
static titleFemale() : string
Tags
Return values
string —titleMale()
public
static titleMale() : string
Tags
Return values
string —toLower()
Converts string to lowercase.
public
static toLower([string $string = '' ]) : string
Uses mb_string extension if available.
Parameters
- $string : string = ''
-
String that should be converted to lowercase
Return values
string —toUpper()
Converts string to uppercase.
public
static toUpper([string $string = '' ]) : string
Uses mb_string extension if available.
Parameters
- $string : string = ''
-
String that should be converted to uppercase
Return values
string —unique()
Chainable method for making any formatter unique.
public
unique([bool $reset = false ][, int $maxRetries = 10000 ]) : UniqueGenerator
// will never return twice the same value
$faker->unique()->randomElement(array(1, 2, 3));
Parameters
- $reset : bool = false
-
If set to true, resets the list of existing values
- $maxRetries : int = 10000
-
Maximum number of retries to find a unique value, After which an OverflowException is thrown.
Tags
Return values
UniqueGenerator —A proxy class returning only non-existing values
valid()
Chainable method for forcing any formatter to return only valid values.
public
valid([Closure $validator = null ][, int $maxRetries = 10000 ]) : ValidGenerator
The value validity is determined by a function passed as first argument.
$values = array();
$evenValidator = function ($digit) {
return $digit % 2 === 0;
};
for ($i=0; $i < 10; $i++) {
$values []= $faker->valid($evenValidator)->randomDigit;
}
print_r($values); // [0, 4, 8, 4, 2, 6, 0, 8, 8, 6]
Parameters
- $validator : Closure = null
-
A function returning true for valid values
- $maxRetries : int = 10000
-
Maximum number of retries to find a unique value, After which an OverflowException is thrown.
Tags
Return values
ValidGenerator —A proxy class returning only valid values
replaceWildcard()
private
static replaceWildcard(mixed $string[, mixed $wildcard = '#' ][, mixed $callback = 'static::randomDigit' ]) : mixed
Parameters
- $string : mixed
- $wildcard : mixed = '#'
- $callback : mixed = 'static::randomDigit'