0

I have a function

function readExcel(){
require_once 'SimpleXLSX.php';
use Shuchkin\SimpleXLSX;

if ( $xlsx = SimpleXLSX::parse('book.xlsx') ) {
    print_r( $xlsx->rows() );
} else {
    echo SimpleXLSX::parseError();
}

But when I call readExcel() I got error

Parse error: syntax error, unexpected token "use"

Help please..

0

1 Answer 1

1

You can't do this. From the manual:

The use keyword must be declared in the outermost scope of a file (the global scope) or inside namespace declarations. This is because the importing is done at compile time and not runtime, so it cannot be block scoped.

A specific example of a use inside a function call (what you are attempting to do) is shown as illegal.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.