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!
Eduardo FuerteDeveloper and AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Eduardo FuerteDeveloper and AnalystAuthor Commented:
Thank you gr8gonzo!

I have to better study PHP7 new features...
0
Eduardo FuerteDeveloper and AnalystAuthor Commented:
Now it's really perfect running.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.