Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #18534

Re: pass parameter to require/class/construct

From Arno Welzel <usenet@arnowelzel.de>
Newsgroups comp.lang.php
Subject Re: pass parameter to require/class/construct
Date 2021-01-20 12:54 +0100
Message-ID <i6qjviFddjrU1@mid.individual.net> (permalink)
References <rtu901$voh$1@gioia.aioe.org> <i6gqcfFg1noU3@mid.individual.net> <ru46dv$2kb$1@gioia.aioe.org>

Show all headers | View raw


alex:

> Il 16/01/21 19:42, Arno Welzel ha scritto:
>> "require" just includes another file, there is result!
> 
> But it is able to return the value returned by the file

Yes, I stand corrected:

<https://www.php.net/manual/en/function.include.php>

"Handling Returns: include returns FALSE on failure and raises a
warning. Successful includes, unless overridden by the included file,
return 1. It is possible to execute a return statement inside an
included file in order to terminate processing in that file and return
to the script which called it. Also, it's possible to return values from
included files. You can take the value of the include call as you would
for a normal function"

Anyway - if you want to have a new class without any parameter in the
constructor, you do not write:

<?php
return new class {
     function __construct($param) {}
};

But just this:

<?php
class MyClass {
     function __construct() {}
};

And when you want to use that class and return an *instance* of this class:

<?php
class MyClass {
     function __construct() {}
};

return new MyClass();




-- 
Arno Welzel
https://arnowelzel.de

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

pass parameter to require/class/construct alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-01-16 09:43 +0100
  Re: pass parameter to require/class/construct John-Paul Stewart <jpstewart@personalprojects.net> - 2021-01-16 11:06 -0500
  Re: pass parameter to require/class/construct "J.O. Aho" <user@example.net> - 2021-01-16 17:38 +0100
    Re: pass parameter to require/class/construct alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-01-18 15:24 +0100
      Re: pass parameter to require/class/construct "J.O. Aho" <user@example.net> - 2021-01-18 17:18 +0100
      Re: pass parameter to require/class/construct Arno Welzel <usenet@arnowelzel.de> - 2021-01-20 12:56 +0100
  Re: pass parameter to require/class/construct Arno Welzel <usenet@arnowelzel.de> - 2021-01-16 19:42 +0100
    Re: pass parameter to require/class/construct alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-01-18 15:36 +0100
      Re: pass parameter to require/class/construct Arno Welzel <usenet@arnowelzel.de> - 2021-01-20 12:54 +0100
        Re: pass parameter to require/class/construct alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-01-20 14:38 +0100

csiph-web