PHP - PHP Deprecated: Methods with the same name as their class will not be constructors

 
Vista:
sin imagen de perfil
Val: 8
Ha aumentado su posición en 18 puestos en PHP (en relación al último mes)
Gráfica de PHP

PHP Deprecated: Methods with the same name as their class will not be constructors

Publicado por noel (2 intervenciones) el 27/10/2019 21:44:40
PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; template has a deprecated constructor in /template.php on line 19

NECESITO AYUDA con este código PHP
----------------------------------------------------------------

((( Esta es mi linea Debajo comienza mi linea 19 ))))

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
class template {
	var $filename = array();
	var $markers = array();
	var $switches = array();
	var $vars = array();
	var $loops = array();
	var $printer = false;
	var $standalone = false;
 
	function template($lang) {
		$this->vars = $lang;
	}
 
	function file($filename) {
		array_push($this->filename, $filename);
	}
 
	function show($marker) {
		$this->markers[$marker] = true;
	}
 
	function switchon($marker) {
		$this->switches[$marker] = true;
	}
 
	function printer() {
		$this->printer = true;
	}
 
	function standalone() {
		$this->standalone = true;
	}
 
	function assign($vars) {
		foreach ($vars as $k => $v)
			$this->vars[$k] = $v;
	}
 
	function loop($loopname, $vars, $object = null) {
		if ($object && gettype($object) == 'array')
			$vars = array_merge($object, $vars);
		else if ($object && gettype($object) == 'object')
			foreach(get_object_vars($object) as $k => $v)
				if (gettype($v) != 'array' && gettype($v) != 'object')
					$vars[$k] = $v;
		if (!isset($this->loops[$loopname]))
			$this->loops[$loopname] = array();
		array_push($this->loops[$loopname], $vars);
	}
 
	function out() {
		// Leer plantilla
		global $user;
		if ($this->printer == true) {
			$lines = file('header_print.tpl');
			foreach ($this->filename as $f)
				$lines = array_merge($lines, file(str_replace('.', '_print.', $f)));
			$lines = array_merge($lines, file('footer_print.tpl'));
		} else {
			$lines = file('header.tpl');
			foreach ($this->filename as $f)
				$lines = array_merge($lines, file($f));
			$lines = array_merge($lines, file('footer.tpl'));
		}
		$html = array();
		$stop = false;
		$stopswitch = false;
		$stoploop = false;
		$stopsubloop = false;
		$loop = '';
		$subloop = '';
 
		// Analice la plantilla y el filtro de acuerdo con la vista de página, bucle y bucle
		foreach ($lines as $line) {
			if (preg_match('/<!--BEGIN ([a-z_]+)-->/', $line, $found)) {
				$stop = isset($this->markers[$found[1]]) ? false : true;
				if ($this->standalone)
					$stop = true;
			} else if (preg_match('/<!--END-->/', $line)) {
				$stop = false;
			} else if (preg_match('/<!--BEGINSWITCH ([a-z_]+)-->/', $line, $found) && !$stop) {
				$stopswitch = isset($this->switches[$found[1]]) ? false : true;
			} else if (preg_match('/<!--ENDSWITCH-->/', $line) && !$stop) {
				$stopswitch = false;
			} else if (preg_match('/<!--BEGINLOOP ([a-z_]+)-->/', $line, $found) && !$stop) {
				$loop = $found[1];
				$looplines = array();
			} else if (preg_match('/<!--ENDLOOP-->/', $line) && !$stop) {
				if (isset($this->loops[$loop])) {
					$class = 'row2';
					foreach ($this->loops[$loop] as $vars) {
						$orig = array();
						$repl = array();
						foreach (array_keys($vars) as $key) {
							$orig[] = '/{'.$loop.".$key}/";
							$repl[] = $vars[$key];
						}
						$orig[] = '/{'.$loop.".class}/";
						$repl[] = $class == 'row1' ? $class = 'row2' : $class = 'row1';
						$store = array();
						foreach ($looplines as $loopline)
							array_push($store, preg_replace($orig, $repl, $loopline));
						foreach ($store as $line) {
							if (preg_match('/<!--BEGINL ([a-z_]+)-->/', $line, $found))
								$stoploop = isset($this->markers[$found[1]]) ? 0 : 1;
							else if (preg_match('/<!--ENDL-->/', $line))
								$stoploop = 0;
							else if (preg_match('/<!--BEGINSUBLOOP ([a-z_]+)([0-9]*)-->/', $line, $found)) {
								$subloop = $found[1].$found[2];
								$subloop_name = $found[1];
								$sublooplines = array();
							} else if (preg_match('/<!--ENDSUBLOOP-->/', $line)) {
								if (isset($this->loops[$subloop])) {
									$subclass = 'row2';
									foreach ($this->loops[$subloop] as $vars) {
										$orig = array();
										$repl = array();
										foreach (array_keys($vars) as $key) {
											$orig[] = '/{'.$subloop_name.".$key}/";
											$repl[] = $vars[$key];
										}
										$orig[] = '/{'.$subloop_name.".class}/";
										$repl[] = $subclass == 'row1' ? $subclass = 'row2' : $subclass = 'row1';
										$substore = array();
										foreach ($sublooplines as $subloopline)
											array_push($substore, preg_replace($orig, $repl, $subloopline));
										foreach ($substore as $line) {
											if (preg_match('/<!--BEGINSL ([a-z_]+)-->/', $line, $found))
												$stopsubloop = isset($this->markers[$found[1]]) ? 0 : 1;
											else if (preg_match('/<!--ENDSL-->/', $line))
												$stopsubloop = 0;
											else if (!$stopsubloop)
												array_push($html, $line);
										}
									}
								}
								$subloop = '';
							} else if ($subloop)
								array_push($sublooplines, $line);
							else if (!$stoploop)
								array_push($html, $line);
						}
					}
				}
				$loop = '';
			} else if ($loop)
				array_push($looplines, $line);
			else if (!$stop && !$stopswitch)
				array_push($html, $line);
		}
 
		$orig = array();
		$repl = array();
 
		// Prepare campos de reemplazo para idiomas y mensajes de error
		foreach ($this->vars as $k => $v) {
			$orig[] = "/{".$k."}/";
			$repl[] = $v;
		}
 
		// Generar secuencia HTML
		$out = '';
		foreach ($html as $h)
			$out .= $h;
 
		$orig[] = "/{[a-z_0-9]+}/";
		$repl[] = '';
 
		// Crear página y salida
		echo preg_replace($orig, $repl, $out);
	}
}
 
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de joel
Val: 3.828
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

PHP Deprecated: Methods with the same name as their class will not be constructors

Publicado por joel (1269 intervenciones) el 28/10/2019 06:56:17
Hola Noel, el problema que tienes, es que en versiones anteriores para crear el constructor se creaba un método con el mismo nombre (que es como tu lo has hecho).

El mensaje te esta diciendo que esto dejara de funcionar en próximas versiones.

Tu tienes puesto:
1
function template($lang) {
y tendría que ser:
1
function __construct($lang) {
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 8
Ha aumentado su posición en 18 puestos en PHP (en relación al último mes)
Gráfica de PHP

PHP Deprecated: Methods with the same name as their class will not be constructors

Publicado por noel (2 intervenciones) el 29/10/2019 03:30:31
Hola hermano, gracias por tu respuesta. Lo cambié a donde me explico Y sucedió que la página no funciona. Si lo desea, puedo dejar la página en un zip para ver cómo lo resolvería. son 16 php en total que hacen funcionar un chat online. sin instalar nada de complicado.
lo interesante, es que no se necesita mucho recurso, y te permite tener un chat online. antes funcionaba muy bien, sigue funcionando. pero con ese error. al cambiarlo a lo que me pidio. deja de funcionar.. lo voy a poner como estaba para que puedas ver que funciona y que es interesante y sensillo. sin usar base de datos ni ningun recurso extra. aquí la página en cuestión.

https://miapk.app/index.php?SMExt=SMPages&SMPagesId=3a7a7e939b1b6c722fcb0231e5c1a100
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar