Всем привет может кто значет как надо сейчас писать классы Я то я что то не совсем пойму. Я поставил PHP 7.1 и он пишет что метод устарел а что именно не знаю "Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Browser has a deprecated constructor in function_user_inform.phpon line 2" Вот образец кода с файла подскажите как правильно оформить (я его сократил не вместился сократил только функции к ним он не придерается) PHP: class Browser { private $_agent = ''; private $_browser_name = ''; private $_version = ''; private $_platform = ''; private $_os = ''; private $_is_aol = false; private $_is_mobile = false; private $_is_robot = false; private $_aol_version = ''; const BROWSER_UNKNOWN = 'unknown'; const VERSION_UNKNOWN = 'unknown'; const BROWSER_OPERA = 'Opera'; // http://www.opera.com/ const BROWSER_OPERA_MINI = 'Opera Mini'; // http://www.opera.com/mini/ const BROWSER_WEBTV = 'WebTV'; // http://www.webtv.net/pc/ const BROWSER_IE = 'Internet Explorer'; // http://www.microsoft.com/ie/ const BROWSER_POCKET_IE = 'Pocket Internet Explorer'; // http://en.wikipedia.org/wiki/Internet_Explorer_Mobile const BROWSER_KONQUEROR = 'Konqueror'; // http://www.konqueror.org/ const BROWSER_ICAB = 'iCab'; // http://www.icab.de/ const BROWSER_OMNIWEB = 'OmniWeb'; // http://www.omnigroup.com/applications/omniweb/ const BROWSER_FIREBIRD = 'Firebird'; // http://www.ibphoenix.com/ const BROWSER_FIREFOX = 'Firefox'; // http://www.mozilla.com/en-US/firefox/firefox.html const BROWSER_ICEWEASEL = 'Iceweasel'; // http://www.geticeweasel.org/ const BROWSER_SHIRETOKO = 'Shiretoko'; // http://wiki.mozilla.org/Projects/shiretoko const BROWSER_MOZILLA = 'Mozilla'; // http://www.mozilla.com/en-US/ const BROWSER_AMAYA = 'Amaya'; // http://www.w3.org/Amaya/ const BROWSER_LYNX = 'Lynx'; // http://en.wikipedia.org/wiki/Lynx const BROWSER_SAFARI = 'Safari'; // http://apple.com const BROWSER_IPHONE = 'iPhone'; // http://apple.com const BROWSER_IPOD = 'iPod'; // http://apple.com const BROWSER_IPAD = 'iPad'; // http://apple.com const BROWSER_CHROME = 'Chrome'; // http://www.google.com/chrome const BROWSER_ANDROID = 'Android'; // http://www.android.com/ const BROWSER_GOOGLEBOT = 'GoogleBot'; // http://en.wikipedia.org/wiki/Googlebot const BROWSER_SLURP = 'Yahoo! Slurp'; // http://en.wikipedia.org/wiki/Yahoo!_Slurp const BROWSER_W3CVALIDATOR = 'W3C Validator'; // http://validator.w3.org/ const BROWSER_BLACKBERRY = 'BlackBerry'; // http://www.blackberry.com/ const BROWSER_ICECAT = 'IceCat'; // http://en.wikipedia.org/wiki/GNU_IceCat const BROWSER_NOKIA_S60 = 'Nokia S60 OSS Browser'; // http://en.wikipedia.org/wiki/Web_Browser_for_S60 const BROWSER_NOKIA = 'Nokia Browser'; // * all other WAP-based browsers on the Nokia Platform const BROWSER_MSN = 'MSN Browser'; // http://explorer.msn.com/ const BROWSER_MSNBOT = 'MSN Bot'; // http://search.msn.com/msnbot.htm // http://en.wikipedia.org/wiki/Msnbot (used for Bing as well) const BROWSER_NETSCAPE_NAVIGATOR = 'Netscape Navigator'; // http://browser.netscape.com/ (DEPRECATED) const BROWSER_GALEON = 'Galeon'; // http://galeon.sourceforge.net/ (DEPRECATED) const BROWSER_NETPOSITIVE = 'NetPositive'; // http://en.wikipedia.org/wiki/NetPositive (DEPRECATED) const BROWSER_PHOENIX = 'Phoenix'; // http://en.wikipedia.org/wiki/History_of_Mozilla_Firefox (DEPRECATED) const PLATFORM_UNKNOWN = 'unknown'; const PLATFORM_WINDOWS = 'Windows'; const PLATFORM_WINDOWS_CE = 'Windows CE'; const PLATFORM_APPLE = 'Apple'; const PLATFORM_LINUX = 'Linux'; const PLATFORM_OS2 = 'OS/2'; const PLATFORM_BEOS = 'BeOS'; const PLATFORM_IPHONE = 'iPhone'; const PLATFORM_IPOD = 'iPod'; const PLATFORM_IPAD = 'iPad'; const PLATFORM_BLACKBERRY = 'BlackBerry'; const PLATFORM_NOKIA = 'Nokia'; const PLATFORM_FREEBSD = 'FreeBSD'; const PLATFORM_OPENBSD = 'OpenBSD'; const PLATFORM_NETBSD = 'NetBSD'; const PLATFORM_SUNOS = 'SunOS'; const PLATFORM_OPENSOLARIS = 'OpenSolaris'; const PLATFORM_ANDROID = 'Android'; const OPERATING_SYSTEM_UNKNOWN = 'unknown'; public function Browser($useragent="") { $this->reset(); if( $useragent != "" ) { $this->setUserAgent($useragent); } else { $this->determine(); } } И т.д /** * Determine the user's platform (last updated 1.7) */ protected function checkPlatform() { if( stripos($this->_agent, 'windows') !== false ) { $this->_platform = self::PLATFORM_WINDOWS; } else if( stripos($this->_agent, 'iPad') !== false ) { $this->_platform = self::PLATFORM_IPAD; } else if( stripos($this->_agent, 'iPod') !== false ) { $this->_platform = self::PLATFORM_IPOD; } else if( stripos($this->_agent, 'iPhone') !== false ) { $this->_platform = self::PLATFORM_IPHONE; } elseif( stripos($this->_agent, 'mac') !== false ) { $this->_platform = self::PLATFORM_APPLE; } elseif( stripos($this->_agent, 'android') !== false ) { $this->_platform = self::PLATFORM_ANDROID; } elseif( stripos($this->_agent, 'linux') !== false ) { $this->_platform = self::PLATFORM_LINUX; } else if( stripos($this->_agent, 'Nokia') !== false ) { $this->_platform = self::PLATFORM_NOKIA; } else if( stripos($this->_agent, 'BlackBerry') !== false ) { $this->_platform = self::PLATFORM_BLACKBERRY; } elseif( stripos($this->_agent,'FreeBSD') !== false ) { $this->_platform = self::PLATFORM_FREEBSD; } elseif( stripos($this->_agent,'OpenBSD') !== false ) { $this->_platform = self::PLATFORM_OPENBSD; } elseif( stripos($this->_agent,'NetBSD') !== false ) { $this->_platform = self::PLATFORM_NETBSD; } elseif( stripos($this->_agent, 'OpenSolaris') !== false ) { $this->_platform = self::PLATFORM_OPENSOLARIS; } elseif( stripos($this->_agent, 'SunOS') !== false ) { $this->_platform = self::PLATFORM_SUNOS; } elseif( stripos($this->_agent, 'OS\/2') !== false ) { $this->_platform = self::PLATFORM_OS2; } elseif( stripos($this->_agent, 'BeOS') !== false ) { $this->_platform = self::PLATFORM_BEOS; } elseif( stripos($this->_agent, 'win') !== false ) { $this->_platform = self::PLATFORM_WINDOWS; } } } Также нашел это но не совсем понял что к чему https://php.ru/manual/migration70.deprecated.html
В качестве конструктора надо использовать не метод, одноименный классу, а метод __construct(), вот и все.
Так чтоли ? не совсем понял Код (Text): class Browser{ private $_os = ''; private $_is_aol = false; private $_is_mobile = false; private $_is_robot = false; private $_aol_version = ''; function __construct() { const BROWSER_UNKNOWN = 'unknown'; const VERSION_UNKNOWN = 'unknown'; const BROWSER_OPERA = 'Opera'; const BROWSER_OPERA_MINI = 'Opera Mini'; } }
Просто переименовать: PHP: public function Browser($useragent = '') на: PHP: public function __construct($useragent = '')
он такой весь... https://github.com/MouseZver/My-garbage-code/blob/master/php.ru/69146/Browser.php PHP: ( new Browser ) -> Browser( $useragent ); --- Добавлено --- Нельзя указывать имя метода аналогично наименованию самого конструктора