18 Pa.C.S. § 3503: Criminal trespass
(a) Buildings and occupied structures.--
(1) A person commits an offense if, knowing that he is not licensed or privileged to do so, he:
(i) enters, gains entry by subterfuge or surreptitiously remains in any building or occupied structure or separately secured or occupied portion thereof; or
(ii) breaks into any building or occupied structure or separately secured or occupied portion thereof.
(2) An offense under paragraph (1)(i) is a felony of the third degree, and an offense under subparagraph (1)(ii) is a felony of the second degree.
(3) As used in this subsection:
"Breaks into." To gain entry by force, breaking, intimidation, unauthorized opening of locks, or through an opening not designed for human access.
(b) Defiant trespasser.--
(1) A person commits an offense if, knowing that he is not licensed or privileged to do so, he enters or remains in any place as to which notice against trespass is given by:
(i) actual communication to the actor;
(ii) posting in a manner prescribed by law or reasonably likely to come to the attention of intruders;
(iii) fencing or other enclosure manifestly designed to exclude intruders;
(iv) notices posted in a manner prescribed by law or reasonably likely to come to the person's attention at each entrance of school grounds that visitors are prohibited without authorization from a designated school, center or program official; or
(v) an actual communication to the actor to leave school grounds as communicated by a school, center or program official, employee or agent or a law enforcement officer.
(2) Except as provided in paragraph (1)(v), an offense under this subsection constitutes a misdemeanor of the third degree if the offender defies an order to leave personally communicated to him by the owner of the premises or other authorized person. An offense under paragraph (1)(v) constitutes a misdemeanor of the first degree. Otherwise it is a summary offense.
(b.1) Simple trespasser.--
(1) A person commits an offense if, knowing that he is not licensed or privileged to do so, he enters or remains in any place for the purpose of:
(i) threatening or terrorizing the owner or occupant of the premises;
(ii) starting or causing to be started any fire upon the premises; or
(iii) defacing or damaging the premises.
(2) An offense under this subsection constitutes a summary offense.
(b.2) Agricultural trespasser.--
(1) A person commits an offense if knowing that he is not licensed or privileged to do so he:
(i) enters or remains on any agricultural or other open lands when such lands are posted in a manner prescribed by law or reasonably likely to come to the person's attention or are fenced or enclosed in a manner manifestly designed to exclude trespassers or to confine domestic animals; or
(ii) enters or remains on any agricultural or other open lands and defies an order not to enter or to leave that has been personally communicated to him by the owner of the lands or other authorized person.
(2) An offense under this subsection shall be graded as follows:
(i) An offense under paragraph (1)(i) constitutes a misdemeanor of the third degree and is punishable by imprisonment for a term of not more than one year and a fine of not less than $250.
(ii) An offense under paragraph (1)(ii) constitutes a misdemeanor of the second degree and is punishable by imprisonment for a term of not more than two years and a fine of not less than $500 nor more than $5,000.
(3) For the purposes of this subsection, the phrase "agricultural or other open lands" shall mean any land on which agricultural activity or farming as defined in section 3309 (relating to agricultural vandalism) is conducted or any land populated by forest trees of any size and capable of producing timber or other wood products or any other land in an agricultural security area as defined in the act of June 30, 1981 (P.L. 128, No. 43), [FN1] known as the Agricultural Area Security Law, or any area zoned for agricultural use.
(c) Defenses.--It is a defense to prosecution under this section that:
(1) a building or occupied structure involved in an offense under subsection (a) of this section was abandoned;
(2) the premises were at the time open to members of the public and the actor complied with all lawful conditions imposed on access to or remaining in the premises; or
(3) the actor reasonably believed that the owner of the premises, or other person empowered to license access thereto, would have licensed him to enter or remain.
(d) Definition.--As used in this section, the term "school grounds" means any building of or grounds of any elementary or secondary publicly funded educational institution, any elementary or secondary private school licensed by the Department of Education, any elementary or secondary parochial school, any certified day-care center or any licensed preschool program.
===========
18 Pa.C.S. § 507: Use of force for the protection of property
(a) Use of force justifiable for protection of property.--The use of force upon or toward the person of another is justifiable when the actor believes that such force is immediately necessary:
(1) to prevent or terminate an unlawful entry or other trespass upon land or a trespass against or the unlawful carrying away of tangible movable property, if such land or movable property is, or is believed by the actor to be, in his possession or in the possession of another person for whose protection he acts; or
(2) to effect an entry or reentry upon land or to retake tangible movable property, if:
(i) the actor believes that he or the person by whose authority he acts or a person from whom he or such other person derives title was unlawfully dispossessed of such land or movable property and is entitled to possession; and
(ii) (A) the force is used immediately or on fresh pursuit after such dispossession; or
(B) the actor believes that the person against whom he uses force has no claim of right to the possession of the property and, in the case of land, the circumstances, as the actor believes them to be, are of such urgency that it would be an exceptional hardship to postpone the entry or reentry until a court order is obtained.
(b) Meaning of possession.--For the purpose of subsection (a) of this section:
(1) A person who has parted with the custody of property to another who refuses to restore it to him is no longer in possession, unless the property is movable and was and still is located on land in his possession.
(2) A person who has been dispossessed of land does not regain possession thereof merely by setting foot thereon.
(3) A person who has a license to use or occupy real property is deemed to be in possession thereof except against the licensor acting under claim of right.
(c) Limitations on justifiable use of force.--
(1) The use of force is justifiable under this section only if the actor first requests the person against whom such force is used to desist from his interference with the property, unless the actor believes that:
(i) such request would be useless;
(ii) it would be dangerous to himself or another person to make the request; or
(iii) substantial harm will be done to the physical condition of the property which is sought to be protected before the request can effectively be made.
(2) The use of force to prevent or terminate a trespass is not justifiable under this section if the actor knows that the exclusion of the trespasser will expose him to substantial danger of serious bodily injury.
(3) The use of force to prevent an entry or reentry upon land or the recaption of movable property is not justifiable under this section, although the actor believes that such reentry or caption is unlawful, if:
(i) the reentry or recaption is made by or on behalf of a person who was actually dispossessed of the property; and
(ii) it is otherwise justifiable under subsection (a)(2).
(4) (i) The use of deadly force is justifiable under this section if:
(A) there has been an entry into the actor's dwelling;
(B) the actor neither believes nor has reason to believe that the entry is lawful; and
(C) the actor neither believes nor has reason to believe that force less than deadly force would be adequate to terminate the entry.
(ii) If the conditions of justification provided in subparagraph (i) have not been met, the use of deadly force is not justifiable under this section unless the actor believes that:
(A) the person against whom the force is used is attempting to dispossess him of his dwelling otherwise than under a claim of right to its possession; or
(B) such force is necessary to prevent the commission of a felony in the dwelling.
(d) Use of confinement as protective force.--The justification afforded by this section extends to the use of confinement as protective force only if the actor takes all reasonable measures to terminate the confinement as soon as he knows that he can do so with safety to the property, unless the person confined has been arrested on a charge of crime.
(e) Use of device to protect property.--The justification afforded by this section extends to the use of a device for the purpose of protecting property only if:
(1) the device is not designed to cause or known to create a substantial risk of causing death or serious bodily injury;
(2) the use of the particular device to protect the property from entry or trespass is reasonable under the circumstances, as the actor believes them to be; and
(3) the device is one customarily used for such a purpose or reasonable care is taken to make known to probable intruders the fact that it is used.
(f) Use of force to pass wrongful obstructor.--The use of force to pass a person whom the actor believes to be intentionally or knowingly and unjustifiably obstructing the actor from going to a place to which he may lawfully go is justifiable, if:
(1) the actor believes that the person against whom he uses force has no claim of right to obstruct the actor;
(2) the actor is not being obstructed from entry or movement on land which he knows to be in the possession or custody of the person obstructing him, or in the possession or custody of another person by whose authority the obstructor acts, unless the circumstances, as the actor believes them to be, are of such urgency that it would not be reasonable to postpone the entry or movement on such land until a court order is obtained; and
(3) the force used is not greater than it would be justifiable if the person obstructing the actor were using force against him to prevent his passage.