Home > database >  Looking for php5 equivalent syntax of php7 functions
Looking for php5 equivalent syntax of php7 functions

Time:10-26

I am in desperate need to find the php5 equivalent for the following functions:

The following error is returned for the below function:

Parse error: syntax error, unexpected '}', expecting ',' or ';'

NOT WORKING EXAMPLE OF BOOL

    private function isFile($data): bool
    {
        return file_exists($data);
    }

I am able to work around this error by removing part of the function : bool but i'm not sure if that's the right way or if that will cause unexpected issues.

WORKING

    private function isFile($data)
    {
        return file_exists($data);
    }

I've got a couple of these php7 functions that end with : bool or : void or : array or : string and none of these work in php5.6, however, if I remove the column and everything after it then the code works, would like confirmation removing those bits is correct or is there a php 5.6 substitute code for the parts removed.

Further examples

NOT WORKING EXAMPLE OF VOID

    private function handleElementClose(Stream $stream): void
    {
        // Skip '</'
        $stream->next(2);
        $element = $stream->readTo('>');

        // Skip '>'
        $stream->next();
        $this->closeElement($stream, $element);
    }

CodePudding user response:

The function file_exists returns a bool value. So removing :bool must be correct. Here is a substitution, considering the unexpected errors because of the return values.

private function isFile($data)
{
    return (bool) file_exists($data);
}
  •  Tags:  
  • php
  • Related