The title may not be totally clear on what I'm trying to do, but I want to include a file into my main file, that included file will have functions in it with namespace classes inside the function. Something like this:
main_file.php
require_once ($inc_path . "functions.inc.php");
require ("/path/to/composer/vendor/autoload.php");
use Netsuite\NetSuiteService;
use NetSuite\Classes\SearchStringField;
$result = ns_customer_exist("customer@email.com", $ns);
print_r ($result);
functions.inc.php:
function ns_customer_exist($email, $ns) {
$searchField = new SearchStringField();
$searchField->operator = "is";
$searchField->searchValue = $email;
$search = new CustomerSearchBasic();
$search->email = $searchField;
$request = new SearchRequest();
$request->searchRecord = $search;
$searchResponse = $ns->search($request);
if($searchResponse->searchResult->status->isSuccess) {
if ($searchResponse->searchResult->totalRecords > 0) {
return $searchResponse->searchResult->recordList->record[0]->internalId;
} else {
return false;
}
} else {
// Todo: return error
return false;
}
}
When I try to run this, I get the error:
[22-Dec-2025 18:27:18 UTC] PHP Fatal error: Uncaught Error: Class "SearchStringField" not found in /path/to/include/functions.inc.php:4
Stack trace:
#0 /path/to/main_file.php(41): ns_customer_exist()
#1 {main}
thrown in /path/to/include/functions.inc.php on line 4
With line 4 being "$searchField = new SearchStringField();"
If I move the function into main_file.php, it works fine. Everything I'm reading tells me that having the function in an include file should work being that I'm calling to use the namespace in the main file, so I don't know if I'm reading the documentation correctly or if I'm misunderstanding it. If I have to, I'll move the functions to the main file, but I'm trying to avoid that as these functions will end up being used in multiple scripts. I'd rather maintain them in one place instead of inside a bunch of scripts. I'd appreciate it if someone can tell me what I'm doing wrong, or if what I want to do is impossible.