Section 505 covers self, Section 506 covers others:
18 Pa. C.S. §505. Use of Force in Self-Protection.
(a) Use of force justifiable for protection of the person. - The use of force upon or toward another person is justifiable when the actor believes that such force is immediately necessary for the purpose of protecting himself against the use of unlawful force by such other person on the present occasion.
(b) Limitations on justifying necessity for use of force.
(1) The use of force is not justifiable under this section:
(i) to resist an arrest which the actor knows is being made by a peace officer, although the arrest is unlawful; or
(ii) to resist force used by the occupier or possessor of property or by another person on his behalf, where the actor knows that the person using the force is doing so under a claim of right to protect the property, except that this limitation shall not apply if:
(A) the actor is a public officer acting in the performance of his duties or a person lawfully assisting him therein or a person making or assisting in a lawful arrest;
(B) the actor has been unlawfully dispossessed of the property and is making a reentry or recaption justified by section 507 of this title(relating to use of force for the protection of property); or
(C) the actor believes that such force is necessary to protect himself against death or serious bodily injury.
(2) The use of deadly force is not justifiable under this section unless the actor believes that such force is necessary to protect himself against death, serious bodily injury, kidnapping or sexual intercourse compelled by force or threat; nor is it justifiable if:
(i) the actor, with the intent of causing death or serious bodily injury, provoked the use of force against himself in the same encounter; or
(ii) the actor knows that he can avoid the necessity of using such force with complete safety by retreating or by surrendering possession of a thing to a person asserting a claim of right thereto or by complying with a demand that he abstain from any action which he has no duty to take, except that:
(A) the actor is not obliged to retreat from his dwelling or place of work, unless he was the initial aggressor or is assailed in his place of work by another person whose place of work the actor knows it to be; and
(B) a public officer justified in using force in the performance of his duties or a person justified in using force in his assistance or a person justified in using force in making an arrest or preventing an escape is not obliged to desist from efforts to perform such duty, effect such arrest or prevent such escape because of resistance or threatened resistance by or on behalf of the person against whom such action is directed.
(3) Except as required by paragraphs (1) and (2) of this subsection, a person employing protective force may estimate the necessity thereof under the circumstances as he believes them to be when the force is used, without retreating, surrendering possession, doing any other act which he has no legal duty to do or abstaining from any lawful action.
(c) 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 safely can, unless the person confined has been arrested on a charge of crime.
18 Pa. C.S. §506. Use of Force for the Protection of Other Persons.
(a) General rule. - The use of force upon or toward the person of another is justifiable to protect a third person when:
(1) the actor would be justified under section 505 of this title (relating to use of force in self-protection) in using such force to protect himself against the injury he believes to be threatened to the person whom he seeks to protect;
(2) under the circumstances as the actor believes them to be, the person whom he seeks to protect would be justified in using such protective force; and
(3) the actor believes that his intervention is necessary for the protection of such other person.
(b) Exceptions. - Notwithstanding subsection (a) of this section:
(1) When the actor would be obliged under section 505 of this title to retreat, to surrender the possession of a thing or to comply with a demand before using force in self-protection, he is not obliged to do so before using force for the protection of another person, unless he knows that he can thereby secure the complete safety of such other person.
(2) When the person whom the actor seeks to protect would be obliged under section 505 of this title to retreat, to surrender the possession of a thing or to comply with a demand if he knew that he could obtain complete safety by so doing, the actor is obliged to try to cause him to do so before using force in his protection if the actor knows that he can obtain complete safety in that way.
(3) Neither the actor nor the person whom he seeks to protect is obliged to retreat when in the dwelling, or place of work of the other to any greater extent than in his own.