what is the use of new() in php?
what is the use of new() in php?
I don't believe that new() is a function in PHP. It is not listed on php.net either. Can you give more information about what you're interested in? Where did you find this information? Or do you have some code you want to understand?
new()with()is a function. Butnewcould be a command (not a function)-- maybe you are thinking about that.
In Object Oriented Programming in PHP, with classes, you can create a new instance of a class with the commandnew.
See this very basic example:
Employee() is a class defined somewhere else.PHP Code:<?php
$john = new Employee();
$sally = new Employee();
?>newcreates an instance of an "employee" (from theEmployee()class).
For more information: http://www.php.net/manual/en/language.oop5.php
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
megha_3000 (01-25-2012)
i got an example of setting up a class that is
its clear but i wanted to be more clear why new instance is used in here. though i m new in php programming so i am a little bit confused.Code:<?php class siteCopyright { // simple function inside my class (function getCopyrightYear() is a method of siteCopyright) function getCopyrightYear() { $var1 = "©"; $var2 = date("Y"); $var3 = "Flash Building"; echo "<h2>$var1$var2 $var3</h2>"; } } // Set new instance of the class, creating an object with that class's properties $myFirstObject = new siteCopyright(); // Now execute the function defined inside our class $myFirstObject -> getCopyrightYear(); ?>
However thanks 4 ur promt reply. if u discuss a little more than i will be greatful.
Last edited by keyboard; 10-01-2012 at 10:05 PM. Reason: Format: [code][/code] Tags
Well Daniel already explained the basics of the new class, but if you want more info check out the OOP tutorials on this youtube channel - http://youtube.com/betterphp
megha_3000 (01-26-2012)
Objects are like "things". You usenewto create an instance of those things.
So with my employee examples above, you can create an instance (stored in a variable) for every employee.
For you, you're creating copyright objects.
What is useful about them is that you can modify them or execute functions in them (called methods in OOP).
But just look at some general tutorials until you understand. It's a significantly different way to program in PHP, but it's very useful.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
megha_3000 (01-26-2012)
Thanks fastsol1 and thanks daniel. Well fastsol1 may i can have some tutorials of html & css. Like these php tutorials. Though i didn't see it yet.But I think i got helpful by these tutorials.
You'll need to search around for html & css tutorials. The channels I surf only deal with php.
megha_3000 (01-28-2012)
Bookmarks