{"id":827,"date":"2016-10-01T17:58:04","date_gmt":"2016-10-01T16:58:04","guid":{"rendered":"http:\/\/duskosavic.com\/blog\/?p=827"},"modified":"2016-10-01T18:00:37","modified_gmt":"2016-10-01T17:00:37","slug":"deprecated-constructor-in-php-class","status":"publish","type":"post","link":"https:\/\/duskosavic.com\/blog\/php\/deprecated-constructor-in-php-class\/","title":{"rendered":"Deprecated Constructor in PHP Class"},"content":{"rendered":"<p>Still converting old PHP code and upgrading to PHP 7.0, I receive a message like this:<\/p>\n<p><code><br \/>\nDeprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Validate_fields has a deprecated constructor in<br \/>\n<\/code><\/p>\n<p>Looking at the code I see this:<\/p>\n<p><code><br \/>\nclass Validate_fields {<br \/>\n\tvar $fields = array();<br \/>\n\tvar $messages = array();<br \/>\n\tvar $check_4html = false;<br \/>\n\tvar $language;<br \/>\n\tvar $time_stamp;<br \/>\n\tvar $month;<br \/>\n\tvar $day;<br \/>\n\tvar $year;<\/p>\n<p>\tfunction Validate_fields() {<br \/>\n\t\t$this->language = \"us\";<br \/>\n\t\t$this->create_msg();<br \/>\n\t}<br \/>\n<\/code><br \/>\nThe message means that the class name <code>Validate_fields<\/code> and the constructor <code>function Validate_fields()<\/code> have the same name. The solution is to use a <code>__constructor()<\/code> instead of <code>function Validate_fields()<\/code>. <br \/>Something like this:<br \/>\n<br \/>\n<code>class Validate_fields {<br \/>\n\tvar $fields = array();<br \/>\n\tvar $messages = array();<br \/>\n\tvar $check_4html = false;<br \/>\n\tvar $language;<br \/>\n\tvar $time_stamp;<br \/>\n\tvar $month;<br \/>\n\tvar $day;<br \/>\n\tvar $year;<\/p>\n<p>\tfunction __constructor() {<br \/>\n\t\t$this->language = \"us\";<br \/>\n\t\t$this->create_msg();<br \/>\n\t}<\/code><br \/>\nThe error is no more. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Still converting old PHP code and upgrading to PHP 7.0, I receive a message like this: Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Validate_fields has a deprecated constructor &hellip; <a href=\"https:\/\/duskosavic.com\/blog\/php\/deprecated-constructor-in-php-class\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[496],"tags":[505,506,499],"series":[],"class_list":["post-827","post","type-post","status-publish","format-standard","hentry","category-php","tag-constructor","tag-deprecated-methods","tag-php-7-0"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Deprecated Constructor in PHP Class - DuskoSavic.com<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/duskosavic.com\/blog\/php\/deprecated-constructor-in-php-class\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Deprecated Constructor in PHP Class - DuskoSavic.com\" \/>\n<meta property=\"og:description\" content=\"Still converting old PHP code and upgrading to PHP 7.0, I receive a message like this: Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Validate_fields has a deprecated constructor &hellip; Continue reading &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/duskosavic.com\/blog\/php\/deprecated-constructor-in-php-class\/\" \/>\n<meta property=\"og:site_name\" content=\"DuskoSavic.com\" \/>\n<meta property=\"article:published_time\" content=\"2016-10-01T16:58:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-10-01T17:00:37+00:00\" \/>\n<meta name=\"author\" content=\"Dusko\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dusko\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/duskosavic.com\\\/blog\\\/php\\\/deprecated-constructor-in-php-class\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/duskosavic.com\\\/blog\\\/php\\\/deprecated-constructor-in-php-class\\\/\"},\"author\":{\"name\":\"Dusko\",\"@id\":\"https:\\\/\\\/duskosavic.com\\\/blog\\\/#\\\/schema\\\/person\\\/5c90e82c5c70eaeee96d0b2efbfd4396\"},\"headline\":\"Deprecated Constructor in PHP Class\",\"datePublished\":\"2016-10-01T16:58:04+00:00\",\"dateModified\":\"2016-10-01T17:00:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/duskosavic.com\\\/blog\\\/php\\\/deprecated-constructor-in-php-class\\\/\"},\"wordCount\":57,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/duskosavic.com\\\/blog\\\/#\\\/schema\\\/person\\\/5c90e82c5c70eaeee96d0b2efbfd4396\"},\"keywords\":[\"constructor\",\"deprecated methods\",\"php 7.0\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/duskosavic.com\\\/blog\\\/php\\\/deprecated-constructor-in-php-class\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/duskosavic.com\\\/blog\\\/php\\\/deprecated-constructor-in-php-class\\\/\",\"url\":\"https:\\\/\\\/duskosavic.com\\\/blog\\\/php\\\/deprecated-constructor-in-php-class\\\/\",\"name\":\"Deprecated Constructor in PHP Class - DuskoSavic.com\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/duskosavic.com\\\/blog\\\/#website\"},\"datePublished\":\"2016-10-01T16:58:04+00:00\",\"dateModified\":\"2016-10-01T17:00:37+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/duskosavic.com\\\/blog\\\/php\\\/deprecated-constructor-in-php-class\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/duskosavic.com\\\/blog\\\/php\\\/deprecated-constructor-in-php-class\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/duskosavic.com\\\/blog\\\/php\\\/deprecated-constructor-in-php-class\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/duskosavic.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Deprecated Constructor in PHP Class\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/duskosavic.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/duskosavic.com\\\/blog\\\/\",\"name\":\"DuskoSavic.com\",\"description\":\"Rapid Mobile Apps Development With Flutter\",\"publisher\":{\"@id\":\"https:\\\/\\\/duskosavic.com\\\/blog\\\/#\\\/schema\\\/person\\\/5c90e82c5c70eaeee96d0b2efbfd4396\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/duskosavic.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/duskosavic.com\\\/blog\\\/#\\\/schema\\\/person\\\/5c90e82c5c70eaeee96d0b2efbfd4396\",\"name\":\"Dusko\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d249b8ea0c85e62fd0339dd1412b99f721f072408db9a9a546efe3a86a93b667?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d249b8ea0c85e62fd0339dd1412b99f721f072408db9a9a546efe3a86a93b667?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d249b8ea0c85e62fd0339dd1412b99f721f072408db9a9a546efe3a86a93b667?s=96&d=mm&r=g\",\"caption\":\"Dusko\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d249b8ea0c85e62fd0339dd1412b99f721f072408db9a9a546efe3a86a93b667?s=96&d=mm&r=g\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Deprecated Constructor in PHP Class - DuskoSavic.com","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/duskosavic.com\/blog\/php\/deprecated-constructor-in-php-class\/","og_locale":"en_US","og_type":"article","og_title":"Deprecated Constructor in PHP Class - DuskoSavic.com","og_description":"Still converting old PHP code and upgrading to PHP 7.0, I receive a message like this: Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Validate_fields has a deprecated constructor &hellip; Continue reading &rarr;","og_url":"https:\/\/duskosavic.com\/blog\/php\/deprecated-constructor-in-php-class\/","og_site_name":"DuskoSavic.com","article_published_time":"2016-10-01T16:58:04+00:00","article_modified_time":"2016-10-01T17:00:37+00:00","author":"Dusko","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Dusko","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/duskosavic.com\/blog\/php\/deprecated-constructor-in-php-class\/#article","isPartOf":{"@id":"https:\/\/duskosavic.com\/blog\/php\/deprecated-constructor-in-php-class\/"},"author":{"name":"Dusko","@id":"https:\/\/duskosavic.com\/blog\/#\/schema\/person\/5c90e82c5c70eaeee96d0b2efbfd4396"},"headline":"Deprecated Constructor in PHP Class","datePublished":"2016-10-01T16:58:04+00:00","dateModified":"2016-10-01T17:00:37+00:00","mainEntityOfPage":{"@id":"https:\/\/duskosavic.com\/blog\/php\/deprecated-constructor-in-php-class\/"},"wordCount":57,"commentCount":0,"publisher":{"@id":"https:\/\/duskosavic.com\/blog\/#\/schema\/person\/5c90e82c5c70eaeee96d0b2efbfd4396"},"keywords":["constructor","deprecated methods","php 7.0"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/duskosavic.com\/blog\/php\/deprecated-constructor-in-php-class\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/duskosavic.com\/blog\/php\/deprecated-constructor-in-php-class\/","url":"https:\/\/duskosavic.com\/blog\/php\/deprecated-constructor-in-php-class\/","name":"Deprecated Constructor in PHP Class - DuskoSavic.com","isPartOf":{"@id":"https:\/\/duskosavic.com\/blog\/#website"},"datePublished":"2016-10-01T16:58:04+00:00","dateModified":"2016-10-01T17:00:37+00:00","breadcrumb":{"@id":"https:\/\/duskosavic.com\/blog\/php\/deprecated-constructor-in-php-class\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/duskosavic.com\/blog\/php\/deprecated-constructor-in-php-class\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/duskosavic.com\/blog\/php\/deprecated-constructor-in-php-class\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/duskosavic.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Deprecated Constructor in PHP Class"}]},{"@type":"WebSite","@id":"https:\/\/duskosavic.com\/blog\/#website","url":"https:\/\/duskosavic.com\/blog\/","name":"DuskoSavic.com","description":"Rapid Mobile Apps Development With Flutter","publisher":{"@id":"https:\/\/duskosavic.com\/blog\/#\/schema\/person\/5c90e82c5c70eaeee96d0b2efbfd4396"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/duskosavic.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/duskosavic.com\/blog\/#\/schema\/person\/5c90e82c5c70eaeee96d0b2efbfd4396","name":"Dusko","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d249b8ea0c85e62fd0339dd1412b99f721f072408db9a9a546efe3a86a93b667?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d249b8ea0c85e62fd0339dd1412b99f721f072408db9a9a546efe3a86a93b667?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d249b8ea0c85e62fd0339dd1412b99f721f072408db9a9a546efe3a86a93b667?s=96&d=mm&r=g","caption":"Dusko"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/d249b8ea0c85e62fd0339dd1412b99f721f072408db9a9a546efe3a86a93b667?s=96&d=mm&r=g"}}]}},"_links":{"self":[{"href":"https:\/\/duskosavic.com\/blog\/wp-json\/wp\/v2\/posts\/827","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/duskosavic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/duskosavic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/duskosavic.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/duskosavic.com\/blog\/wp-json\/wp\/v2\/comments?post=827"}],"version-history":[{"count":4,"href":"https:\/\/duskosavic.com\/blog\/wp-json\/wp\/v2\/posts\/827\/revisions"}],"predecessor-version":[{"id":831,"href":"https:\/\/duskosavic.com\/blog\/wp-json\/wp\/v2\/posts\/827\/revisions\/831"}],"wp:attachment":[{"href":"https:\/\/duskosavic.com\/blog\/wp-json\/wp\/v2\/media?parent=827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/duskosavic.com\/blog\/wp-json\/wp\/v2\/categories?post=827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/duskosavic.com\/blog\/wp-json\/wp\/v2\/tags?post=827"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/duskosavic.com\/blog\/wp-json\/wp\/v2\/series?post=827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}