Laravel use of PHP Linked List implementation SplDoublyLinkedList();


I come from Java Language where there are Linked List implementations easy to use.

As I know all the Data Structure theory, I know it's more efficient to use dynamic memory so I search and I find this PHP Double Linked List Implementation which I think is fine, Also, I read if it is a good practice to implement this concept in PHP, where some people says that the Double Linked List implementation has better memory performance, and other people says that don't. So I want to try myself who is right.

I am using Laravel and I want to use this PHP List implementation,so I got this Controller Function:

public function save(){
        $people = new People;

        $list = SplDoublyLinkedList();
        $list.push(request()->all());
        //To iterate the list
        for($list->rewind();$list->valid();$list->next()){
         echo $list->current()."<br/>";
         }
        echo "<br/>";

    }

Then I got this error "Fatal error: Class 'App\Http\Controllers\SplDoublyLinkedList' not found" , If this is an already implemented data structure, I don't want to create it again, that is one solution to my error, I know. But I looking for more optimized solutions.

What Do I miss here? What do I need to add to laravel? Any Advice? Any Experience with this? All you have to solution or advice, Thank you.

Answer

You can call it like $list = new \SplDoublyLinkedList.
You can also add a use statement above your class: use SplDoublyLinkedList;
And then you can call it like you did $list = new SplDoublyLinkedList;

When you call it like $list = new SplDoublyLinkedList it will look in your current namespace for that class. Since it can't find it, it throws an exception.

source: stackoverflow.com
js interview questions