Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves Laravel Error: Class UDPSocket cannot extend final class Socket #26

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

GWNetwork
Copy link

I imported Condenser into a Laravel Framework 10 project and I got the error "Class UDPSocket cannot extend final class Socket". I troubleshooted it for a few hours and then realized that it might be a name conflict. So first I changed UDPSocket.php and changed:
class UDPSocket extends Socket {
to: class UDPSocket extends scSocket {

Then in socket.php I changed:
abstract class Socket {
to: abstract class scSocket {

Then TCPSocket.php I changed:
class TCPSocket extends Socket {
to: class TCPSocket extends scSocket {

This worked!

Also to get it working on Laravel 10 with Php 8 I also modified my composer.json with different versions:
"require": {
"monolog/monolog": "~3.5"

"require-dev": {
"phpunit/phpunit": "^10.1",

and removed phpdocumentor, not sure what that breaks?
Note, I didn't modify the composer.json file in the pull request.

Renamed Socket to scSocket to avoid conflict with Laravel framework built in class name.
Renamed Socket to scSocket to avoid conflict with Laravel framework built in class name.
Renamed Socket to scSocket to avoid conflict with Laravel framework built in class name.
@dpi
Copy link
Contributor

dpi commented Nov 21, 2023

This can’t be a thing. The library operates in its own namespace. If you’re using Composer and its autoloader you shouldn’t be having any issues.

The Socket class here is abstract, not final. It sounds like you’re pulling in the files manually and removing or mixing namespaces oddly causing conflicts with an existing finalised Socket class.

Seems unlikely to be caused by this project.

@GWNetwork
Copy link
Author

So this came about when I restored an old project which worked quite a few years ago. I installed the latest laravel, php and condenser library. When i first tested it, I set it up in composer and composer was generating the exact same error message. E.g. when I typed the command in the debian shell 'composer update'. So then I temporarily removed the condenser autoload entries - 'files' and 'psr-4', which got past the composer error. But then when I tried to run a server query via my php code I got the error again. I thought the issue was related to laravel, like it somehow loaded another socket class that conflicted. Because it was saying the class was 'final', but when I checked it the condenser class is not set as 'final'. That gave me the idea to use a different class name, which solved it. I am not an expert on these things, but I got it working so got inspired to do a pull request. So I think Laravel is the cause but I understand if you guys decide not to use the changes. I guess If someone finds my fork from a google search, then that should be enough. cheers

@GWNetwork
Copy link
Author

also, as you mention, technically what you said was correct. I was pulling in the files manually. I was adding the composer parts myself to an already populated comopser file (which gets filled by laravel). Im then calling the extension using a Controller. Using commands like:
use SourceServer
use MasterServer;
use SteamId;
Doing that everything works except for the socket class name conflict.

@dpi
Copy link
Contributor

dpi commented Nov 22, 2023

For Composer dependencies you shouldn't be touching those yourself. Especially entries in lockfiles or the autoloader. The composer command should managed those fully. That also means that the files in your vendor directory populated by Composer, which includes the files from this library, must not be touched. If you do need to work on a modified version of this library, consider forking this repo to your on github account, or creating a local repo. Instructions to set those up are in Composer repositories documentation.

Composer errors are probably dependency / conflicts? in which case you do need to resolve those on your own. I doubt Laravel has an odd setup for Composer, so getting this library should be a matter of composer require in your root directory. Perhaps ask around in the Laravel community, but of course paste in the messages that Composer is spitting out.

@GWNetwork
Copy link
Author

I replied to you before with 2 messages at once, I feel you may have missed the first one?
But to summarise from your message: The composer error was the same as the function error I got: Class UDPSocket cannot extend final class Socket.
I did create a fork and the changes I made already fixed my issue. I did use composer require to add Condenser, next time I can reference my own fork if I ever install it again or need to update my composer. I had to change the versions of some other libraries because those older versions were too old for the dependencies Laravel was using. I do not edit lockfiles. The reason I suggested the pull request was because I thought it would not effect the main branch functionality, but it definitely does resolve the issue with socket class name for anyone trying to use Condenser with the laravel framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants