Home > Net >  Class "App\Http\Controllers\SplStack" not found
Class "App\Http\Controllers\SplStack" not found

Time:05-31

I am new to laravel here i am trying using php splstack on laravel for word to number convert but when i run this code so that its give like this error. i am trying to use splstack but i have not any idea to how to use it. so that i will finding some solution on stack

$stack = new SplStack; // Currently not working
             $sum   = 0; // Running total
            $last  = null;
            // echo '<pre>';print_r($parts);echo '</pre>';die;
            foreach ($parts as $part) {
                if (!$stack->isEmpty()) {
                    if ($stack->top() > $part) {
                        if ($last >= 1000) {
                            $sum  = $stack->pop();
                            $stack->push($part);
                        } else {
                            $stack->push($stack->pop()   $part);
                        }
                    } else {
                        $stack->push($stack->pop() * $part);
                    }
                } else {
                    $stack->push($part);
                }
                $last = $part;
            }

CodePudding user response:

import the SplStack class on top of your controller like as: use SplStack; or change your object creation by this. new \SplStack.

Read more from here https://www.php.net/manual/en/class.splstack.php

CodePudding user response:

In order to use another controller in your file, you need to "import" it first. You must specify the controller and it's filepath. Such as, you need to write this at the top of your file if you wish to use a controller called LoginController:

use App\Http\Controllers\LoginController;

I do not know where SplStack is located so I can not specify your path for you. But you must write the full path in order to import the file. I also suggest reading the documentation a bit more before engaging in coding to avoid future issues. You seem to be just starting to learn.

  • Related