PHP Deprecated: Methods with the same name

Php

Php Problem Overview


I am getting an error saying

>Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; TSStatus has a deprecated constructor in C:\Program Files (x86)\Zend\Apache24\htdocs\viewer\modules\tsstatus\tsstatus.php on line 10

class TSStatus is line 10 plus at the bottom TSStatus shows

class TSStatus
{
	private $_host;
	private $_queryPort;
	private $_serverDatas;
	private $_channelDatas;
	private $_userDatas;
	private $_serverGroupFlags;
	private $_channelGroupFlags;
	private $_login;
	private $_password;
	private $_cacheFile;
	private $_cacheTime;
	private $_channelList;
	private $_useCommand;
	private $_javascriptName;
	private $_socket;

	public $imagePath;
	public $showNicknameBox;
	public $timeout;
	public $hideEmptyChannels;
	public $hideParentChannels;

	public function TSStatus($host, $queryPort)

    ...
}

Php Solutions


Solution 1 - Php

As mentioned in the error, the official manual and the comments:

Replace

public function TSStatus($host, $queryPort)

with

public function __construct($host, $queryPort)

Solution 2 - Php

I was getting warnings, about this problem, and now it start to work. At first it was:

function Smarty()
{
  $this->assign('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME']
                : @$GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']);

But I made this way:

function _construct()
    {
      $this->assign('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME']
                    : @$GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']);

Now I've stoped getting warnings and the script is working well.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser6301557View Question on Stackoverflow
Solution 1 - PhpManfred RadlwimmerView Answer on Stackoverflow
Solution 2 - PhpHugo RomoView Answer on Stackoverflow