0

Is it possible to define a function and use without ()?

Like require("a.php") and require "a.php".

function getNameById($id){}; /*and use it like*/ $id = getNameById "1";

Thanks.

3
  • 5
    and why would you do that? it's not like PHP needs to be compressed like JS. Commented Mar 25, 2012 at 14:42
  • It wouldn't really benefit from looking like VB6, either. Commented Mar 25, 2012 at 14:43
  • I have an function that loads classes and namespaces. Like import("a.b.c"); I want to do like import "a.b.c"; or import a.b.c. Like in Java or using a.b.c; like .NET. Commented Mar 25, 2012 at 14:51

4 Answers 4

8

No, it isn't. require is a language construct, just like echo, print, include, etc.

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

Comments

3

No, that's not possible. require is a language construct; not a function.

Comments

2

require is a special language construct, not a function, and no, it's not possible.

Comments

1

As other have mention, require and for example echo, isset and empty are language constructs. Which means that it is built into the php core.

The only way you can create your own constructs is by writing a php extension in C. So to answer your question, not in pure php.

1 Comment

Thanks a lot Mattias.. I will try to do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.