Tattat
Tattat

Reputation: 15778

Is there "Java Bean" like technology in PHP?

Is there something like the Java Bean stuff in PHP? Thank you.

Upvotes: 2

Views: 5426

Answers (5)

wildcards
wildcards

Reputation: 61

java bean is good for managing your resource as it implement the right MVC framework. here are a simple tutorial to implement it on PHP.

https://webdevchoices.wordpress.com/2011/08/21/applying-bean-pattern-in-php-programming/

and here is a snippet for those who are to lazy to click the link

class Person {
private $_firstName;
private $_lastName;

public function setFirstName($value) {
    $v = trim($value);
    $this->_firstName = empty($v) ? null : $v;
}

public funtion getFirstName() {
    return $this->_firstName;
}

public function setLasttName($value) {
    $v = trim($value);
    $this->_lastName = empty($v) ? null : $v;
}

public funtion getLastName() {
    return $this->_lastName;
}

}

Upvotes: -1

kingtut007
kingtut007

Reputation: 89

In PHP MVC frameworks such as CakePHP, ZF, Symfony etc...you could say that the equivalent of a JavaBean would be the Model itself (the M) of MVC. A model is where you would have the get / set functionalities that javabeans do. Just FYI, in Symfony, that is called an "entity"

Upvotes: 4

John Essential Njue
John Essential Njue

Reputation: 19

Have you heard about red bean php?

Try it and you will experience a great new world.

http://redbeanphp.com/

A great php ORM

Upvotes: 0

pleasedontbelong
pleasedontbelong

Reputation: 20102

not by default... but frameworks are something similar because the framework (usually) allows you to to map the POST or GET, build forms and save the info into the db, according to a Model... Like when using beans.. =)

Upvotes: 0

Mark Grey
Mark Grey

Reputation: 10257

Just going off the info you provided, if by similar to JavaBeans you mean a reusable directory of classes and objects that conform to reasonably unified standards then the closest thing I think would be PEAR.

Upvotes: 2

Related Questions