ext/sockets: Set default values for socket_create parameters #14207
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request proposes a modification to the
socket_createfunction in the PHP Socket extension to set default values for thedomain,type, andprotocolparameters if the user doesn't provide any arguments.Changes:
domainparameter is set toAF_INET(IPv4) on Windows systems, andAF_UNIX(Unix domain sockets) on non-Windows systems.typeparameter is set toSOCK_STREAM(TCP).protocolparameter is set toSOL_TCP.If the user provides arguments to the
socket_createfunction, those values will override the default values set by this change.Motivation:
The current behavior of the
socket_createfunction requires users to explicitly provide all three parameters, even in common use cases where the default values would suffice. By setting sensible default values based on the operating system and common use cases, this change aims to simplify socket programming for developers and reduce the need for redundant code.Testing and Compatibility:
I have performed local testing with various use cases, and the changes seem to work as intended. However, more extensive testing, particularly with existing codebases and edge cases, is recommended to ensure compatibility and identify any potential issues.