Skip to content
Advertisement

Tag: class

Get class name minus namespace without using Reflection

Is there a simple way to get the class name without the namespace without using Reflection? This is my class and when I call get_class() I get CRMPiccoBundleServicesRFCWebhookSiteCancelled Answer Or simply exploding the return from class_name and getting the last element: Or simply removing the namespace from the output of get_class: Either works with or without namespace. And so on.

Variable variables in classes using PHP 7

Actually I’m migrating a bigger project from PHP 5.3.3 to PHP 7.1.13. In older versions of PHP it was possible to code following access to variable variables: This shows: Using the same code in PHP 7 it shows: In PHP 7 I figured out, that I have to use this way to get the same result: I found in the

What am I doing wrong with my optional PHP arguments?

I have a the following class: So from my interpretation I should be able to pass either $id or $humanIdentifier to that constructor, neither or both if I wanted. However, when I call the code below I am finding that its the $id in the constructor args being set to hello world and not the $humanIdentifier, despite me specifying the

Create instances of all classes in a directory with PHP

I have a directory with several PHP files consisting of classes with the same names as the files. (Sample.php’s class will be called Sample.) Each of these classes have a function called OnCall(). How can I create an instance of every class in my directory and execute all of their OnCall()s? I cannot do it manually ($sample = new Sample();

PHP Classes: Should I use 2 classes or 1?

I am currently trying to make a class that deals with a survey in PHP (Drupal). So far I have this: This is great, I can create a new instance of Survey, set the properties, and call save on it. However, I also want to be able to have methods that retrieve the results of these surveys from the DB

understanding why echo doesnt work within a php class function

I’m trying to debug a class and using print_r and echo to view the variables as the script progresses. However for some reason I can’t seem to get any output from within the function, i’ve declared the function public but can’t get any output using print, echo or print_r. I’m misunderstanding something fundamental here – can anyone help please. here’s

Advertisement