Reputation: 480
Few of my friend said that traditional way of programming can conflict. For an Example I have created and input box and submit button like this
<form name="sample" method="post">
<input type="text" name="name"/>
<input type="submit" />
</form>
<?php
if(isset($_POST['name']){
$name=$_POST['name'];
echo $name;}
?>
Now there if three user example tom,jerry and spike enter them name and press submit at the same time is the result can conflict? I have also heard that writing on OOP dose not conflicts. Is it true? If I have to write the same program in OOP the how it will be? Thanks,
Upvotes: 0
Views: 139
Reputation: 26
As was mentioned, three people submitting a form at the same time will not cause a conflict with what you are doing - simply echoing the inputted value. The way PHP works is to give Tom, Jerry, and Spike each their own $name
.
As for an object-oriented approach, the final approach would depend on the scope of your project.
class Person
{
private $_name;
public function __construct( $name )
{
$this->_name = $name;
}
public function WhoAmI()
{
echo $this->_name;
}
}
$myPerson = new Person( $_POST['name'] );
$myPerson->WhoAmI();
Upvotes: 1
Reputation:
What you've heard is nonsensical and wrong. Variables are not shared between invocations of a PHP script; multiple users accessing this script at once would not see inconsistent results.
There is absolutely no difference between OOP and non-OOP PHP programming in this regard.
Upvotes: 1
Reputation: 2200
It won't conflict with other users, since every user has his own "Session". OOP is used to make specific classes to make handling a specific object easier.
Example if you have multiple users it might be easier to use an OOP class.
class User {
$name;
function __construct( $name ) {
$this->name = $name;
}
function getName() {
return $this->name;
}
}
I would really recommend to look at this url: http://php.net/manual/en/language.oop5.php
Upvotes: 2