Emilio Lopez
asked on
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP
Hi experts, i'm getting some errors or warnings on my Web page since the hosting company upgrade the version of php. I understand that the code needs to be changed but I'm lost.
can you guys help me?
thank you in advance.
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; g_twitter_feed has a deprecated constructor in /nas/content/live/bdgalard o/wp-conte nt/plugins /shortcode sdex/inclu des/widget s/twitter- feed.php on line 9
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; generosity_Recent_Post_Thu mbnail has a deprecated constructor in /nas/content/live/bdgalard o/wp-conte nt/themes/ generosity /widgets/r ecent-post .php on line 9
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; generosity_Popular_Post_Th umbnail has a deprecated constructor in /nas/content/live/bdgalard o/wp-conte nt/themes/ generosity /widgets/p opular-pos t.php on line 9
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; generosity_Slider_Gallery has a deprecated constructor in /nas/content/live/bdgalard o/wp-conte nt/themes/ generosity /widgets/g allery-sli der.php on line 9
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; generosity_Tags_Cloud_C has a deprecated constructor in /nas/content/live/bdgalard o/wp-conte nt/themes/ generosity /widgets/t ags-cloud- number.php on line 9
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /nas/content/live/bdgalard o/wp-conte nt/plugins /js_compos er/include /classes/c ore/class- vc-mapper. php on line 111
can you guys help me?
thank you in advance.
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; g_twitter_feed has a deprecated constructor in /nas/content/live/bdgalard
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; generosity_Recent_Post_Thu
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; generosity_Popular_Post_Th
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; generosity_Slider_Gallery has a deprecated constructor in /nas/content/live/bdgalard
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; generosity_Tags_Cloud_C has a deprecated constructor in /nas/content/live/bdgalard
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /nas/content/live/bdgalard
Sure. So in older versions of PHP, when class constructors were functions that just had the same name as the class, like this:
So when I created/constructed new instances of these classes, it would look for the methods with the same names as the classes (so when creating new instances, the Automobile class would run the Automobile() method and the Fruit class would run the Fruit() method):
In newer versions of PHP, instead of the method's name being the same as the class, you just use the method name __construct():
That's usually all there is to it. The usage stays the same:
class Automobile
{
public function Automobile()
{
echo "A new automobile has been created!";
}
}
class Fruit
{
public function Fruit()
{
echo "Yum!";
}
}
So when I created/constructed new instances of these classes, it would look for the methods with the same names as the classes (so when creating new instances, the Automobile class would run the Automobile() method and the Fruit class would run the Fruit() method):
<?php
$toyota = new Automobile(); // This echoes "A new automobile has been created!"
$watermelon = new Fruit(); // This echoes "Yum!"
?>
In newer versions of PHP, instead of the method's name being the same as the class, you just use the method name __construct():
class Automobile
{
public function __construct()
{
echo "A new automobile has been created!";
}
}
class Fruit
{
public function __construct()
{
echo "Yum!";
}
}
That's usually all there is to it. The usage stays the same:
<?php
$toyota = new Automobile(); // This echoes "A new automobile has been created!"
$watermelon = new Fruit(); // This echoes "Yum!"
?>
ASKER
Thank you so much guys for your help.
I'm very sorry to come back until now
So, in the example below the error is found on line 7 that contains this: class g_twitter_feed extends WP_Widget {
As I understand I need to change the line 8 than contains this: function g_twitter_feed()
And change it for this: function __construct()
Thank you again
I'm very sorry to come back until now
So, in the example below the error is found on line 7 that contains this: class g_twitter_feed extends WP_Widget {
As I understand I need to change the line 8 than contains this: function g_twitter_feed()
And change it for this: function __construct()
Thank you again
- <?php
- add_action('widgets_init',
'g_twitter_feed_widgets'); - function g_twitter_feed_widgets()
- {
- register_widget('g_twitter
_feed'); - }
- class g_twitter_feed extends WP_Widget {
- function g_twitter_feed()
- {
- $widget_ops = array('classname' => 'widget-tweets', 'description' => 'Slideshow of twitter feed.');
- $control_ops = array('id_base' => 'twitter_feed-widget');
- parent::__construct('twitt
er_feed-wi dget' , __('(theme)Twitter Feed Slider','generosity'),$wid get_ops,$c ontrol_ops ); - }
- function widget($args, $instance)
- {
- extract($args);
- $title = apply_filters('widget_titl
e', $instance['title']); - $number = esc_attr($instance['number
']); - $username = esc_attr($instance['userna
me']); - echo wp_kses_post($before_widge
t); - if($args['id']=='footer-1'
||$args['i d']=='foot er-2'||$ar gs['id']== 'footer-3' ||$args['i d']=='foot er-4'): - if($title) {
- echo wp_kses_post($before_title
) . $title . $after_title; - }
- ?>
- <!-- tweet Slider -->
- <div class="tweets-slider" data-username="<?php echo esc_attr($username) ?>" data-count="<?php echo esc_attr($number) ?>">
- </div>
- <?php else:
- if($title) {
- echo wp_kses_post($before_title
) . $title . $after_title; - }
- ?>
- <span class="float-username"><a href="https://twitter.com/<?php echo esc_attr($username) ?>">@<?php echo esc_attr($username) ?></a> <i class="fa fa-twitter"></i></span>
- <!-- tweet Slider -->
- <div class="tweet feeds" data-username="<?php echo esc_attr($username) ?>" data-count="<?php echo esc_attr($number) ?>"></div>
- <?php
- endif;
- echo wp_kses_post($after_widget
); - }
- function update($new_instance, $old_instance)
- {
- $instance = $old_instance;
- $instance['title'] = strip_tags($new_instance['
title']); - $instance['number'] = $new_instance['number'];
- $instance['username'] = $new_instance['username'];
- return $instance;
- }
- function form($instance)
- {
- $defaults = array('title' => 'Latest Tweet', 'number' => 3, 'username' => 'username');
- $instance = wp_parse_args((array) $instance, $defaults); ?>
- <p>
- <label for="<?php echo esc_attr($this->get_field_
id('title' )); ?>"><?php _e('Title:','generosity') ?></label> - <input class="widefat" style="width: 216px;" id="<?php echo esc_attr($this->get_field_
id('title' )); ?>" name="<?php echo esc_attr($this->get_field_ name('titl e')); ?>" value="<?php echo esc_attr($instance['title' ]); ?>" /> - </p>
- <p>
- <label for="<?php echo esc_attr($this->get_field_
id('userna me')); ?>"><?php _e('Username:','generosity ') ?></label> - <input class="widefat" style="width: 180px;" id="<?php echo esc_attr($this->get_field_
id('userna me')); ?>" name="<?php echo esc_attr($this->get_field_ name('user name')); ?>" value="<?php echo esc_attr($instance['userna me']); ?>" /> - </p>
- <p>
- <label for="<?php echo esc_attr($this->get_field_
id('number ')); ?>"><?php _e('Number of tweets to show:','generosity') ?></label> - <input class="widefat" style="width: 30px;" id="<?php echo esc_attr($this->get_field_
id('number ')); ?>" name="<?php echo esc_attr($this->get_field_ name('numb er')); ?>" value="<?php echo esc_attr($instance['number ']); ?>" /> - </p>
- <?php
- }
- }
- ?>
Correct. There's always a slim chance there's something more than that, but that's the first step you should take, and check for errors afterwards.
ASKER
Thank you gr8gonzo
The error disappears but now I get a new one :(
Warning: include(/nas/content/live/ bdgalardo/ wp-content /themes/ge nerosity/w idgets/rec ent-post.p hp): failed to open stream: No such file or directory in /nas/content/live/bdgalard o/wp-conte nt/themes/ generosity /functions .php on line 4
Warning: include(): Failed opening '/nas/content/live/bdgalar do/wp-cont ent/themes /generosit y/widgets/ recent-pos t.php' for inclusion (include_path='.:/usr/shar e/php') in /nas/content/live/bdgalard o/wp-conte nt/themes/ generosity /functions .php on line 4
<?php
require_once get_template_directory().' /framework /vafpress/ bootstrap. php';
include get_template_directory().( '/widgets/ recent-pos t.php'); 'this is the line 4 of functions.php
include get_template_directory().( '/widgets/ popular-po st.php');
include get_template_directory().( '/widgets/ gallery-sl ider.php') ;
include get_template_directory().' /widgets/t ags-cloud- number.php ';
require_once(get_template_ directory( ).('/inclu de/wp_boot strap_navw alker.php' ));
include(get_template_direc tory().'/i nclude/hel per.php');
The error disappears but now I get a new one :(
Warning: include(/nas/content/live/
Warning: include(): Failed opening '/nas/content/live/bdgalar
<?php
require_once get_template_directory().'
include get_template_directory().(
include get_template_directory().(
include get_template_directory().(
include get_template_directory().'
require_once(get_template_
include(get_template_direc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Ryan and gr8gonzo
Yes, I'll contact the hosting company.
Yes, I'll contact the hosting company.
ASKER
Thank you guys, I really appreciate it.
Deprecated features in PHP 7.0.x
https://www.php.net/manual/en/migration70.deprecated.php