cakephp PHP 5.4.4 [duplicate] - php

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Declaration of Methods should be Compatible with Parent Methods in PHP
I just installed php 5.4.4. and I all of a sudden get a strict warning.
Does someone know what it is?
Strict (2048): Declaration of User::beforeSave() should be compatible with Model::beforeSave($options = Array) [APP/Model/User.php, line 3]

In APP/Model/User.php, change the declaration to match the class it extends, Model
function beforeSave( array $options ){
...

If you look closely, you'll notice that the methods signature differs. Model::beforeSave() accepts an optional array, whilst your method doesn't accept anything.
However, the message is not severe. It's a strict, meaning that you're breaking standards, but is not like you're on Titanic.

Related

PHP param type hinted with '?' [duplicate]

This question already has answers here:
What is the purpose of the question marks before type declaration in PHP7 (?string or ?int)?
(4 answers)
Closed 3 years ago.
I was reading through some of the Zend framework's hydration source code and came across something I haven't encountered before:
public function hydrate(string $name, ?array $data = null) : string
I've never seen something type hinted like the $data parameter - ?array
I don't know what to search for, so finding documentation on the syntax used there is really difficult. Does anyone know what it is called when you type hint with a question mark like that, and possibly what it does?
Even if you only point me at the right documentation I'd really appreciate any help.
It declares $data as nullable, as described in the docs

PHP syntax - what's this? [duplicate]

This question already has answers here:
Colon after method declaration?
(2 answers)
Closed 4 years ago.
It's almost impossible for me to search for an answer to this as I don't know what this syntax is called.
I have a server running a relatively old version of PHP (5.5.38) and I'm getting parse errors when I run a file that has the following:
public function foo(): array
{
...specifically the : array suffix.
Can anyone tell me what this syntax is called (so I can research further) and which PHP version introduced it?
This was added in PHP 7, they're called return type declarations.
http://php.net/manual/en/functions.returning-values.php#functions.returning-values.type-declaration

What does prepending '&' to a function name mean in PHP? [duplicate]

This question already has answers here:
What does it mean to start a PHP function with an ampersand?
(3 answers)
Closed 7 years ago.
I'm using a CMS package written in PHP. In one of it's core files I saw following line that is for defining a function in a class body.
public static function &getLib($sClass, $aParams = array()) {
// Code
}
I didn't understand why the function name 'getLib' has been prepended with the ampersand(&) sign? I've never seen such thing before.
Can someone please explain me in detail why such thing has been done and what's the benefit it has over simply using the function name?
It means the function should return a reference to a variable rather than just the value itself.

Why doesn't end(( )) throw a strict notice? [duplicate]

This question already has answers here:
Parentheses altering semantics of function call result
(2 answers)
Closed 8 years ago.
end(array_keys(array(0))) says PHP Strict standards: Only variables should be passed by reference ( http://3v4l.org/CNLVT )
end((array_keys(array(0)))) on the other hand, just works ( http://3v4l.org/168fi ). Why?
The VLD decompiler shows the same opcodes being ran the only difference is in the ext column but I can't find documentation on what that means.
What's likely happening is array_keys is passing the result back by reference. As such, PHP is throwing you a notice that you shouldn't do that.
Wrapping in parenthesis actually changes the reference and forces PHP to evaluate the statement inside first. As such, it removes the reference. One of those weird things that doesn't look like it makes a difference but actually does.
More on the weirdness here http://phpsadness.com/sad/51

PHP: why are some internal functions missing from `get_defined_functions`? [duplicate]

This question already has answers here:
What is the difference between a language construct and a "built-in" function in PHP?
(4 answers)
Closed 8 years ago.
PHP has a large number of batteries-included functions, e.g. functions on arrays. Some of these, like each, are present in get_defined_functions()['internal']. Others, like reset and many others, are not present at all. However, they are treated as functions in every other way: they are not documented as "language constructs" or keywords; I can call them using the "variable function" feature; function_exists("reset") returns true; if I try to redefine them (e.g. function reset() { ... }), I get an error about redeclaration, rather than a syntax error; and so on.
Why are these functions not listed by get_defined_functions? Are they not actually functions? If not, what are they? If they are functions, then what actually is it that get_defined_functions is listing? In either case, how do I list the things that don't appear in get_defined_functions?
Quite a short answer: Reset is present in get_defined_functions()['internal'].
Look at [1532] in this fiddle: http://phpfiddle.org/main/code/h5n-ndx

Categories