• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 33
  • Last Modified:

Could you point a work around to this PHP7 error: Message: Methods with the same name as their class will not be constructors in a future version of PHP; xxx_model has a deprecated constructor ?

Hi Experts

Could you point a work around to this PHP7 error: Message: Methods with the same name as their class will not be constructors in a future version of PHP; xxx_model has a deprecated constructor ?

Accordingly to:
img001
The CodeIgniter's  code:
<?php
    class Camaras_model extends CI_Model{
        var $conf;
        function camaras_model(){
           
             $this->conf= array(
                'start_day'=>'monday',
                'day_type'=>'abr',
                'show_next_prev'=>true,
                'next_prev_url'=>base_url().'camarashome/agenda',
                );
             $this->conf['template'] = '

Open in new window


Thanks in advance!
0
Eduardo Fuerte
Asked:
Eduardo Fuerte
  • 2
1 Solution
 
gr8gonzoConsultantCommented:
So the way classes -used- to work in PHP is :

class MyClass
{
  function MyClass()
  {
    echo "This is the constructor - it runs whenever you create a new instance of MyClass.";
  }
}

The constructor method would just have the same name as the class, so if you ran this:
$x = new MyClass();
// OUTPUT: This is the constructor - it runs whenever you create a new instance of MyClass.

Open in new window



The newer methodology is that ALL class constructors have a special name called __construct:

class MyClass
{
  function __construct()
  {
    echo "This is the constructor - it runs whenever you create a new instance of MyClass.";
  }
}

class YourClass
{
  function __construct()
  {
    echo "This is the constructor - it runs whenever you create a new instance of YourClass.";
  }
}

So just change:
function camaras_model(){

Open in new window

to:
function __construct(){

Open in new window


And the warning should go away.
0
 
Eduardo FuerteAuthor Commented:
Thank you gr8gonzo!

I have to better study PHP7 new features...
0
 
Eduardo FuerteAuthor Commented:
Now it's really perfect running.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now