> For the complete documentation index, see [llms.txt](https://php7.shujuwajue.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://php7.shujuwajue.com/php-70x-xin-te-xing/bing-qi-yi-xie-lao-shi-de-xie-fa.md).

# 补充\*摒弃一些老式的写法

> 参考:[Deprecated features in PHP 7.0.x](http://php.net/manual/zh/migration70.deprecated.php)

## 摒弃一些老式的写法

### 目录:

* 摒弃老式构造函数的写法
* 摒弃静态调用非静态方法
* 摒弃password\_hash() salt 的选项写法
* 摒弃 capture\_session\_meta SSL上下文选项写法
* LDAP的用法 - 摒弃使用 [ldap\_sort()](http://php.net/manual/zh/function.ldap-sort.php) 函数(被废弃)

### 摒弃老式构造函数的写法

从php4开始，构造函数的便可以通过命名保持与类名一致的方式来声明自己是构造函数。这种方式一直被沿用到php5.6。但是在PHP7中，不推荐,官方已经说会在未来删除。

```php
<?php
class Info
{
    public function info()
    {
        echo "I am just a normal class method";
    }
}

$info = new Info();
$info->info();
```

使用\_\_construct方法

```php
<?php
class Info
{

    public function __construct()
    {
        echo "I am default constructor";
    }
}

$info = new Info();
$info->info();
```

### 摒弃静态调用非静态方法

静态调用的方法不声明的静态是过时的，或许未来会删除。

```php
<?php
class foo {
    function bar() {
        echo 'I am not static!';
    }
}

foo::bar();
?>
```

以上例程会输出：

```
Deprecated: Non-static method foo::bar() should not be called statically in - on line 8
I am not static!
```

### 摒弃password\_hash() salt 的选项写法

password\_hash()函数的salt选项已经被弃用，以防止开发人员生成他们自己(通常不安全的) salt。当开发人员不提供salt 时，该函数本身生成一个加密安全的salt，因此不应该需要定制的salt 生成。

### 摒弃 capture\_session\_meta SSL上下文选项写法

capture\_session\_meta SSL上下文选项已经被弃用。现在，通过stream\_get\_meta\_data()函数可以使用SSL元数据。

### LDAP的用法 - 摒弃使用 [ldap\_sort()](http://php.net/manual/zh/function.ldap-sort.php) 函数(被废弃)

下面的函数已经被废弃：

* [ldap\_sort()](http://php.net/manual/zh/function.ldap-sort.php)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://php7.shujuwajue.com/php-70x-xin-te-xing/bing-qi-yi-xie-lao-shi-de-xie-fa.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
