I'm trying to do something like this:
function doSomething($param, Class) { Class::someFunction(); } $someVar = doSomething($param, Class);
Is it possible?
To explain better what I'm trying to do. I have a helper function in Laravel to generate unique slugs, so I have to query different tables depending on where the slug is going to be saved.
Actual code I'm trying to write:
$newcat->slug = $helper->uniqueSlug($appname, Apk); public function uniqueSlug($str, Apk) { $slug = Str::slug($str); $count = Apk::whereRaw("slug RLIKE '^{$slug}(-[0-9]+)?$'")->count(); return $count ? "{$slug}-{$count}" : $slug; }
Thanks!
Passing and Returning Objects in C++ In C++ we can pass class's objects as arguments and also return them from a function the same way we pass and return other variables. No special keyword or header file is required to do so.
yes of coarse you can pass classes or functions or even modules ...
We can pass Object of any class as parameter to a method in java. We can access the instance variables of the object passed inside the called method. It is good practice to initialize instance variables of an object before passing object as parameter to method otherwise it will take default initial values.
You can pass an object as an argument to a function, in the usual way.
You can use the magic ::class
constant:
public function uniqueSlug($str, $model) { $slug = Str::slug($str); $count = $model::whereRaw("slug RLIKE '^{$slug}(-[0-9]+)?$'")->count(); return $count ? "{$slug}-{$count}" : $slug; } $newcat->slug = $helper->uniqueSlug($appname, Apk::class);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With