You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `init` parameter specifies a function that will be called when the module is initialized, and the `shutdown` parameter specifies a function that will be called when the module is shut down. Both parameters are optional; you can specify either one, both, or none.
280
-
281
-
The specified functions should be defined in your Go code:
275
+
To define an initialization function, tag it with `//export_php:module init`:
282
276
283
277
```go
278
+
//export_php:module init
284
279
funcinitializeModule() {
285
-
// Perform initialization tasks
286
-
// For example, set up global resources, initialize data structures, etc.
280
+
// Perform initialization tasks
281
+
// For example, set up global resources, initialize data structures, etc.
287
282
}
283
+
```
284
+
285
+
To define a shutdown function, tag it with `//export_php:module shutdown`:
288
286
287
+
```go
288
+
//export_php:module shutdown
289
289
funccleanupModule() {
290
-
// Perform cleanup tasks
291
-
// For example, free resources, close connections, etc.
290
+
// Perform cleanup tasks
291
+
// For example, free resources, close connections, etc.
292
292
}
293
293
```
294
294
295
+
You can define either one, both, or none of these functions. The initialization function will be called when the PHP module is loaded, and the shutdown function will be called when the PHP module is unloaded.
296
+
295
297
### Declaring Constants
296
298
297
299
The generator supports exporting Go constants to PHP using two directives: `//export_php:const` for global constants and `//export_php:classconstant` for class constants. This allows you to share configuration values, status codes, and other constants between Go and PHP code.
0 commit comments