Selection Sort in PHP With Example | How does selection sort work in PHP ?
Insertion Sort in PHP With Example | How Does Insertion Sort Work in PHP
PHP null In Hindi | PHP is null Function
PHP object Type Casting In Hindi | PHP object In Hindi
Calculator In Jquery In Hindi | jQuery Calculator In Hindi
Back end developer roadmap : how to became back end developer ? back end development kya hai?
If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
PHP में stdClass
एक generic empty class है जिसमे dynamic properties & methods होती हैं , dynamic का मतलब है आप need के according properties को add या remove कर सकते हैं।
PHP stdClass
stdClass
के objects को new
operator या object typecast करके किया जा सकता है। कई सारे PHP functions जैसे json_decode(), mysqli_fetch_object() या PDOStatement::fetchObject() भी इसी class के instances को create करते हैं।
<?php
$obj = new stdClass;
$obj->name = "Babu Rao";
$obj->age = 50;
?>
same Object instance का use करके आप सभी properties को access कर सकते हैं।
echo "Name : {$obj->name}"; \\ Babu Rao
echo "Age : {$obj->age}"; \\ 50
हालाँकि अगर आप चाहे तो methods को भी add कर सकते हैं लेकिन methods को call करने का तरीका थोड़ा different होता है।
क्योंकि हम method को एक value की तरह assign कर रहे हैं , तो उसी तरह से call भी करेंगे।
Example
<?php
$obj = new stdClass;
// assign method.
$obj->speak = function() {
echo "Utha le re BABA";
};
// now call the method.
($obj->speak)();
//or
$speak = $obj->speak;
$speak();
?>
Output
Utha le re BABA Utha le re BABA
Next , आप need के according parameters भी define कर सकते हैं।
<?php
$obj = new stdClass;
// assign method.
$obj->speak = function($talk) {
echo $talk . "\n";
};
// pass value.
($obj->speak)("Kaho han !");
//or
$speak = $obj->speak;
$speak("150 rupaya dega");
?>
Output
Kaho han ! 150 rupaya dega
ध्यान रहे add की गए method के अंदर आप किसी external variable को directly access नहीं कर सकते हैं। external variable को access करने के लिए आपको use
keyword का use करना पड़ेगा।
<?php
$obj = new stdClass;
$ex_var = "External variable";
$obj->speak = function() use ($ex_var) {
echo $ex_var;
};
($obj->speak)();
?>
Output
External variable
stdClass Object से properties को delete करने के लिए unset() Function का use किया जाता है।
<?php
$obj = new stdClass;
$obj->name = "Babu Rao";
$obj->age = 50;
echo "Before : ";
var_dump($obj);
// remove age.
unset($obj->age);
echo "After : ";
var_dump($obj);
?>
Output
Before : object(stdClass)#1 (2) { ["name"]=> string(8) "Babu Rao" ["age"]=> int(50) } After : object(stdClass)#1 (1) { ["name"]=> string(8) "Babu Rao" }
var_dump()
function किसी variable के structure / information जैसे stored value उसका type , length etc. के बारे में बताता है।
Read more about var_dump() ...
I Hope, आपको PHP में stdClass
के बारे में अच्छे से समझ आ गया होगा।
Loading ...
Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.
Get connected with me. :) LinkedIn Twitter Instagram Facebook