### Version Information
Source: https://github.com/php/doc-zh/blob/master/_autodocs/configuration-reference.md
Examples of how to get and compare PHP version information.
```php
// PHP version
phpversion(); // "8.2.0"
phpversion('pdo'); // "8.2.0"
// Check version
version_compare(PHP_VERSION, '8.0.0', '>='); // true
// Constants
PHP_VERSION; // "8.2.0"
PHP_VERSION_ID; // 80200
PHP_MAJOR_VERSION; // 8
PHP_MINOR_VERSION; // 2
PHP_RELEASE_VERSION; // 0
PHP_OS; // "Linux"
PHP_OS_FAMILY; // "Linux"
PHP_INT_MAX; // 9223372036854775807
PHP_FLOAT_MAX; // 1.7976931348623E+308
```
--------------------------------
### Time Limits Configuration
Source: https://github.com/php/doc-zh/blob/master/_autodocs/configuration-reference.md
Examples of setting and getting the maximum execution time for a script.
```php
// Set execution time limit
set_time_limit(300); // 5 minutes
set_time_limit(0); // No limit
// Get limit
$limit = ini_get('max_execution_time');
```
--------------------------------
### Production Configuration Example
Source: https://github.com/php/doc-zh/blob/master/_autodocs/configuration-reference.md
Example php.ini settings for a production environment.
```php
// php.ini (production)
error_reporting = E_ALL
display_errors = 0
log_errors = 1
error_log = /var/log/php-errors.log
memory_limit = 256M
upload_max_filesize = 50M
post_max_size = 100M
max_execution_time = 60
session.cookie_secure = 1
session.cookie_httponly = 1
session.cookie_samesite = Strict
```
--------------------------------
### Development Configuration Example
Source: https://github.com/php/doc-zh/blob/master/_autodocs/configuration-reference.md
Example php.ini settings for a development environment.
```php
// php.ini (development)
error_reporting = E_ALL
display_errors = 1
log_errors = 1
error_log = /var/log/php-errors.log
xdebug.mode = develop,debug
xdebug.start_with_request = trigger
```
--------------------------------
### Runtime Configuration Functions
Source: https://github.com/php/doc-zh/blob/master/_autodocs/configuration-reference.md
Examples of using PHP functions to get, set, and restore configuration directives at runtime.
```php
// Get directive value
$value = ini_get('memory_limit'); // "128M"
$value = ini_get_all(); // All directives
// Set directive value
ini_set('memory_limit', '256M');
ini_set('error_reporting', 'E_ALL');
// Restore default
ini_restore('memory_limit');
// Check if value can be changed
$result = ini_alter('memory_limit', '256M');
// Get current settings
phpinfo();
phpinfo(INFO_CONFIGURATION);
```
--------------------------------
### CURLFile Usage Example
Source: https://github.com/php/doc-zh/blob/master/_autodocs/curl-reference.md
Usage Example for CURLFile.
```php
$file = new CURLFile('upload.pdf', 'application/pdf');
```
--------------------------------
### Environment Variables and Superglobals
Source: https://github.com/php/doc-zh/blob/master/_autodocs/configuration-reference.md
Examples of accessing environment variables and superglobal arrays in PHP.
```php
// Environment variables
$path = $_ENV['PATH'];
$user = $_ENV['USER'];
getenv('HOME'); // Get environment variable
// Query parameters
$id = $_GET['id'];
$search = $_GET['q'];
// POST data
$name = $_POST['name'];
$email = $_POST['email'];
// Cookies
$session = $_COOKIE['PHPSESSID'];
// Superglobals
$_REQUEST; // GET, POST, COOKIE combined
$_FILES; // Uploaded files
$_SESSION; // Session data (after session_start)
$_SERVER; // Server info
$GLOBALS; // Global variables
```
--------------------------------
### Usage of Security Directives
Source: https://github.com/php/doc-zh/blob/master/_autodocs/configuration-reference.md
Example of how to set security-related directives in php.ini.
```php
// php.ini
open_basedir = /var/www/html
disable_functions = exec,passthru,shell_exec,system,proc_open
disable_classes = DirectoryIterator
```
--------------------------------
### DateInterval Class Usage Example
Source: https://github.com/php/doc-zh/blob/master/_autodocs/datetime-reference.md
Example demonstrating how to create and format DateInterval objects.
```php
// Create 3 day interval
$interval = new DateInterval('P3D');
// Create from date string
$interval = DateInterval::createFromDateString('next Monday');
// Format output
echo $interval->format('%d days, %h hours');
```
--------------------------------
### DateTime Class Usage Example
Source: https://github.com/php/doc-zh/blob/master/_autodocs/datetime-reference.md
Example demonstrating how to create, format, modify, and calculate differences using the DateTime class.
```php
// Create DateTime object
$dt = new DateTime('2024-01-15 14:30:00');
// Format for output
echo $dt->format('Y-m-d H:i:s');
// Modify the date
$dt->modify('next Monday');
$dt->add(new DateInterval('P1D'));
// Get difference between dates
$now = new DateTime();
$interval = $dt->diff($now);
echo $interval->format('%d days');
```
--------------------------------
### Recommended Production Settings
Source: https://github.com/php/doc-zh/blob/master/_autodocs/configuration-reference.md
Recommended php.ini settings for a production environment.
```ini
error_reporting = E_ALL
display_errors = 0
log_errors = 1
error_log = /var/log/php-errors.log
memory_limit = 256M
max_execution_time = 60
upload_max_filesize = 50M
post_max_size = 50M
session.cookie_secure = 1
session.cookie_httponly = 1
session.cookie_samesite = Strict
open_basedir = /var/www/html
disable_functions = exec,passthru,shell_exec,system,proc_open
```
--------------------------------
### Recommended Development Settings
Source: https://github.com/php/doc-zh/blob/master/_autodocs/configuration-reference.md
Recommended php.ini settings for a development environment.
```ini
error_reporting = E_ALL
display_errors = 1
memory_limit = 256M
max_execution_time = 300
upload_max_filesize = 100M
post_max_size = 100M
```
--------------------------------
### 创建目录
Source: https://github.com/php/doc-zh/blob/master/README.md
创建一个目录,把我们需要的所有工具和 repos 放在里面,以便开始为文档做贡献:
```bash
mkdir ~/php-docs
cd ~/php-docs
```
--------------------------------
### PDO Default Settings
Source: https://github.com/php/doc-zh/blob/master/_autodocs/configuration-reference.md
While there are no direct php.ini settings for PDO, you can configure error modes at runtime.
```php
// No direct php.ini settings, but can configure at runtime
$pdo = new PDO($dsn, $user, $pass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
```
--------------------------------
### 获取文档仓库
Source: https://github.com/php/doc-zh/blob/master/README.md
克隆官方文档仓库以供本地使用。
```bash
mkdir phpdoc
cd phpdoc
git clone git@github.com:php/doc-en.git en
git clone git@github.com:php/doc-zh.git zh
git clone git@github.com:php/doc-base.git
```
--------------------------------
### DateTime Class Methods
Source: https://github.com/php/doc-zh/blob/master/_autodocs/datetime-reference.md
Reference for the methods available in the DateTime class.
```php
class DateTime implements DateTimeInterface {
public __construct(string $datetime = "now", ?DateTimeZone $timezone = null)
public static createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null): DateTime|false
public static createFromImmutable(DateTimeImmutable $object): static
public static getLastErrors(): array|false
public format(string $format): string
public modify(string $modifier): static
public add(DateInterval $interval): static
public sub(DateInterval $interval): static
public getTimezone(): DateTimeZone|false
public setTimezone(DateTimeZone $timezone): static
public getOffset(): int
public setDate(int $year, int $month, int $day): static
public setTime(int $hour, int $minute, int $second = 0, int $microsecond = 0): static
public setISODate(int $year, int $week, int $dayOfWeek = 1): static
public diff(DateTimeInterface $targetDate, bool $absolute = false): DateInterval
}
```
--------------------------------
### 翻译文件头示例 (新文件)
Source: https://github.com/php/doc-zh/blob/master/README.md
根据获取的 commit hash 和你的用户名,构建新的翻译文件头。
```xml
```
--------------------------------
### CREDITS 示例
Source: https://github.com/php/doc-zh/blob/master/README.md
有时也可以加入这样一行来记录贡献者。
```xml
```
--------------------------------
### DocBook 格式示例
Source: https://github.com/php/doc-zh/blob/master/README.md
XML 文件是文档的原始文件,其格式为 DocBook。
```xml
```
--------------------------------
### DateInterval Class Properties and Methods
Source: https://github.com/php/doc-zh/blob/master/_autodocs/datetime-reference.md
Reference for the properties and methods of the DateInterval class.
```php
class DateInterval {
public int $y;
public int $m;
public int $d;
public int $h;
public int $i;
public int $s;
public float $f;
public bool $invert;
public int|false $days;
public __construct(string $duration)
public static createFromDateString(string $datetime): DateInterval|false
public format(string $format): string
}
```
--------------------------------
### CurlHandle Resource
Source: https://github.com/php/doc-zh/blob/master/_autodocs/curl-reference.md
Resource handle for cURL operations (returned by curl_init).
```php
// Not a class but a resource type in PHP < 8.0
// In PHP 8.0+, it's CurlHandle object
$ch = curl_init('https://example.com');
```
--------------------------------
### 修改后的文件头部示例
Source: https://github.com/php/doc-zh/blob/master/README.md
展示了更新 EN-Revision commit hash 和添加 CREDITS 后的 XML 文件头部。
```xml
```
--------------------------------
### XML 文件段落示例(英文原文)
Source: https://github.com/php/doc-zh/blob/master/README.md
展示了英文 XML 文件中关于 Windows 平台支持的段落,用于说明中文翻译中的空格和换行问题。
```xml
This section applies to Windows 95/98/Me and
Windows NT/2000/XP. Do not expect PHP to work on
16 bit platforms such as Windows 3.1. Sometimes
we refer to the supported Windows platforms as Win32.
```
--------------------------------
### XML 文件段落示例(中文翻译 - 潜在问题)
Source: https://github.com/php/doc-zh/blob/master/README.md
展示了中文翻译中可能出现的,由于保留原文格式导致的不希望的空格问题。
```xml
本节内容适用于 Windows 95/98/Me 以及 Windows NT/2000/XP。
PHP 不能在 16 位平台例如 Windows 3.1 下运行。有时我们把
支持 PHP 的 Windows 平台称为 Win32。
```
--------------------------------
### XML 文件段落示例(中文翻译 - 解决空格问题)
Source: https://github.com/php/doc-zh/blob/master/README.md
展示了通过将翻译结果全部放到同一行来解决中文翻译中空格问题的方法。
```xml
本节内容适用于 Windows 95/98/Me 以及 Windows NT/2000/XP。PHP 不能在 16 位平台例如 Windows 3.1 下运行。有时我们把支持 PHP 的 Windows 平台称为 Win32。
```
--------------------------------
### 获取 Commit Hash
Source: https://github.com/php/doc-zh/blob/master/README.md
假设你想翻译 `in_array()` 函数的文档,但这个函数在中文文档中还不存在,切换到 `en` 目录,然后执行此命令获取 commit hash。
```bash
git log -n1 --pretty=format:%H -- reference/array/functions/in-array.xml
```
--------------------------------
### XML 文件段落示例(中文翻译 - 兼顾可读性)
Source: https://github.com/php/doc-zh/blob/master/README.md
展示了在中文翻译中,通过在保留的英文单词前后换行来解决空格问题,同时兼顾原始 XML 文件可读性的方法。
```xml
本节内容适用于 Windows 95/98/Me 以及
Windows NT/2000/XP。PHP 不能在 16 位平台例如
Windows 3.1 下运行。有时我们把支持
PHP 的 Windows 平台称为 Win32。
```
--------------------------------
### diff 示例
Source: https://github.com/php/doc-zh/blob/master/README.md
展示了如何使用 diff 命令查看文件差异,特别是 `password_needs_rehash()` 函数的参数类型从字符串变为整数和数组的变化。
```diff
diff --git a/reference/password/functions/password-needs-rehash.xml b/reference/password/functions/password-needs-rehash.xml
index 984eb2dc5c..860758a4a4 100644
--- a/reference/password/functions/password-needs-rehash.xml
+++ b/reference/password/functions/password-needs-rehash.xml
@@ -12,8 +12,8 @@
booleanpassword_needs_rehash
stringhash
- stringalgo
- stringoptions
+ integeralgo
+ arrayoptions
This function checks to see if the supplied hash implements the algorithm
```
--------------------------------
### DateTimeImmutable Class Methods
Source: https://github.com/php/doc-zh/blob/master/_autodocs/datetime-reference.md
Reference for the methods available in the DateTimeImmutable class.
```php
class DateTimeImmutable implements DateTimeInterface {
public __construct(string $datetime = "now", ?DateTimeZone $timezone = null)
public static createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null): DateTimeImmutable|false
public static createFromMutable(DateTime $object): static
public static getLastErrors(): array|false
public format(string $format): string
public modify(string $modifier): static
public add(DateInterval $interval): static
public sub(DateInterval $interval): static
// ... additional methods identical to DateTime
}
```
--------------------------------
### 原始文件头示例
Source: https://github.com/php/doc-zh/blob/master/README.md
展示了翻译前的文件头部,包含 EN-Revision commit hash 和 Maintainer 信息。
```xml
```
--------------------------------
### CURLStringFile Class (PHP 8.1+)
Source: https://github.com/php/doc-zh/blob/master/_autodocs/curl-reference.md
Represents a string to upload as a file via cURL.
```php
class CURLStringFile {
public function __construct(
string $data,
string $postname,
string $mime_type = 'application/octet-stream'
)
}
```
--------------------------------
### 翻译文件头示例
Source: https://github.com/php/doc-zh/blob/master/README.md
为便于跟踪翻译工作以及保持与英文文档一致,请用以下两行代替原来英文文档的前两行。
```xml
```
--------------------------------
### CURLFile Class
Source: https://github.com/php/doc-zh/blob/master/_autodocs/curl-reference.md
Represents a file to upload via cURL.
```php
class CURLFile {
public function __construct(
string $filename,
?string $mime_type = null,
?string $posted_filename = null
)
public function getFilename(): string
public function getMimeType(): string
public function getPostFilename(): string
public function setMimeType(string $mime_type): void
public function setPostFilename(string $posted_filename): void
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.