Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. how to get a object according the name of class

how to get a object according the name of class

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
tutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Keanu L
    wrote on last edited by
    #1

    how to implement like this:

    $classname = "dsa";$ob = new $classname();

    i just have a var of the class name and how to new the class?

    G U 2 Replies Last reply
    0
    • K Keanu L

      how to implement like this:

      $classname = "dsa";$ob = new $classname();

      i just have a var of the class name and how to new the class?

      G Offline
      G Offline
      Graham Breach
      wrote on last edited by
      #2

      You have the right syntax for doing that in your example. There are some helpful functions for working with classes: Class functions[^]. The class_exists[^] function is useful for checking if you have a valid class name.

      K 1 Reply Last reply
      0
      • K Keanu L

        how to implement like this:

        $classname = "dsa";$ob = new $classname();

        i just have a var of the class name and how to new the class?

        U Offline
        U Offline
        User 9742811
        wrote on last edited by
        #3

        Did u tried it yours before posting? That works for me: class A {} $classname = "A"; $obj = new $classname; if it is not your question then clear it.

        1 Reply Last reply
        0
        • G Graham Breach

          You have the right syntax for doing that in your example. There are some helpful functions for working with classes: Class functions[^]. The class_exists[^] function is useful for checking if you have a valid class name.

          K Offline
          K Offline
          Keanu L
          wrote on last edited by
          #4

          Thanks. It works.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups