हाँ जब वस्तु बनाई गई है निर्माता कहा जाता है। क्यों यह प्रयोग किया जाना चाहिए एक सवाल यह भी पूछा, एक वास्तविक जीवन उदाहरण के एक डेटाबेस वर्ग है, जहां वस्तु के साथ फोन:
एक निर्माता की उपयोगिता का एक छोटा सा उदाहरण इस
class Bar
{
// The variable we will be using within our class
var $val;
// This function is called when someone does $foo = new Bar();
// But this constructor has also an $var within its definition,
// So you have to do $foo = new Bar("some data")
function __construct($var)
{
// Assign's the $var from the constructor to the $val variable
// we defined above
$this->val = $var
}
}
$foo = new Bar("baz");
echo $foo->val // baz
// You can also do this to see everything defined within the class
print_r($foo);
अद्यतन है कनेक्ट करने के लिए कनेक्ट करने वाला उपयोगकर्ता नाम और पासवर्ड और तालिका। फिर आपके पास उस डेटाबेस के भीतर सभी काम करने के लिए कार्य हैं।
स्रोत
2008-12-31 18:47:59
इसके अलावा, http://stackoverflow.com/questions/403756/benefits-of-using-a-constructor देखें जो एक ही प्रश्न – Adam
हेक्टेयर से पूछता है, यह उल्लसित है। यही मेरा सवाल है कि मैं पूरी तरह से भूल गया। मैं अपने प्रश्न पूछते समय संबंधित प्रश्नों को देख रहा था और कुछ भी नहीं देखा। क्षमा करें क्योंकि मैं इस प्रश्न को हटा नहीं सकता क्योंकि बहुत सारे उत्तर हैं। –
2 साल शेष, कुछ भी नहीं हुआ)) – zerkms