
171 Cal.App.3d 265 (1985)
217 Cal. Rptr. 284
HERB GROSS et al., Petitioners,
v.
THE SUPERIOR COURT OF THE CITY AND COUNTY OF SAN FRANCISCO, Respondent; VICTORIA MEWS CONSORTIUM, Real Party in Interest.
Docket No. A028012.
Court of Appeals of California, First District, Division Two.
August 20, 1985.
*268 COUNSEL
Robert De Vries for Petitioners.
No appearance for Respondent.
Dennis C. Hyde, Charles Stuhr, Miller, Starr & Regalia, Harry D. Miller and Dennis C. Hyde for Real Party in Interest.
Steven Alan Beilock and Beilock, Collins & Beeson as Amicus Curiae on behalf of Real Party in Interest.
OPINION
SMITH, J.
Real party in interest purchased the subject premises at a trustee's sale, conducted pursuant to a power of sale contained in a deed of trust, and thereafter brought an unlawful detainer against the existing tenants, petitioners, for restitution of the premises. Petitioners defended on the basis that none of the grounds to evict under a local rent stabilization ordinance existed. The municipal court, deciding for real party, concluded that the rent stabilization ordinance was preempted by state law and on appeal the superior court affirmed this judgment. Petitioners seek mandamus from this court to compel the superior court to vacate its decision affirming the judgment of the municipal court and to enter judgment in their favor. The writ of mandate shall issue.

FACTS
Real party in interest, Victoria Mews Consortium, a California corporation, is engaged in the construction and sale of new condominiums. The subject premises, a condominium, was sold as a new unit. Real party in interest received a note secured by a deed of trust, recorded May 11, 1979, as part of the consideration for the sale. The debt secured by this note was junior to a loan from an institutional lender. The purchasers of the condominium rented the condominium to petitioners pursuant to a written one-year lease executed September 15, 1982.
*269 Thereafter, and during the term of the lease, the purchasers of the condominium defaulted in their obligations owed to both the first lender and the real party in interest. Real party commenced foreclosure and took title to the subject premises pursuant to a trustee's sale conducted on March 8, 1983.
After purchasing the property at the trustee's sale, real party in interest served petitioners with a three-day notice to vacate the premises based solely upon Code of Civil Procedure section 1161a. The municipal court decided in favor of real party and on June 6, 1984, the appellate department of the superior court issued a judgment affirming the decision of the lower court and refused certification. On July 13, 1984, petitioners filed the instant petition. (1) (See fn. 1.) An alternative writ was issued on September 24, 1984, and on December 6, 1984, this court denied a motion to dismiss on the ground of mootness.[1]
The basic question in this case is whether a tenant can be evicted from a unit under rent control by an owner who purchased at a trustee's sale and at a time subsequent to the execution of the relevant lease when none of the rent stabilization ordinance grounds permitting eviction are present.

I
Section 37.9(a) of the San Francisco rent control ordinance provides that "A landlord shall not endeavor to recover possession of a rental unit unless:" (1) The tenant has failed to pay rent; (2) The tenant has violated an obligation of the tenancy; (3) The tenant is committing a nuisance; (4) The tenant is using the unit for an illegal purpose; (5) The tenant has refused to agree to a new rental agreement upon expiration of the old one; (6) The tenant has refused access to the landlord; (7) The tenant is a subtenant not approved by the landlord; (8) The landlord seeks possession for use as a principal residence for himself or specified relatives; (9) The landlord seeks to recover possession in order to sell the unit as a condominium; (10) The landlord seeks to remove the rental unit from the market for demolition, after obtaining permits; (11) The landlord seeks to temporarily remove the unit from housing use for capital improvements or rehabilitation work; or (12) The landlord seeks to recover possession in order to carry out substantial rehabilitation. The ordinance does not list as a ground for eviction a *270 change of ownership pursuant to either a judicial foreclosure proceeding or a trustee's sale.
The municipal court held this ordinance inapplicable on the ground that it is in conflict with the general laws of the state. The court found preemption by virtue of Code of Civil Procedure section 1161a which allows eviction by an unlawful detainer proceeding where the property has been sold through foreclosure or where the property has been sold under a power of sale contained in a deed of trust.[2]
We disagree. (2a) The Supreme Court in Birkenfeld v. City of Berkeley (1976) 17 Cal.3d 129 [130 Cal. Rptr. 465, 550 P.2d 1001], considered whether Code of Civil Procedure section 1161 conflicted with limitations upon eviction in a Berkeley rent control statute. The court observed that "Code of Civil Procedure section 1161, subdivision 1, makes the continuation of a tenant's possession after expiration of the term a form of unlawful detainer for which the landlord may recover possession in summary proceedings under Code of Civil Procedure section 1164 et seq. However, these statutory provisions are not necessarily in conflict with the charter amendment's provision forbidding landlords to recover possession upon expiration of a tenancy if the purpose of the statutes is sufficiently distinct from that of the charter amendment. (See Galvan v. Superior Court [1969] 70 Cal.2d 851, 859 [76 Cal. Rptr. 642, 452 P.2d 930]; People v. Mueller [1970] 8 Cal. App.3d 949, 954 [88 Cal. Rptr. 157].) The purpose of the unlawful detainer statutes is procedural. The statutes implement the landlord's property rights by permitting him to recover possession once the consensual basis for the tenant's occupancy is at an end. In contrast the *271 charter amendment's elimination of particular grounds for eviction is a limitation upon the landlord's property rights under the police power, giving rise to a substantive ground of defense in unlawful detainer proceedings. The mere fact that a city's exercise of the police power creates such a defense does not bring it into conflict with the state's statutory scheme. Thus ... the statutory remedies for recovery of possession and of unpaid rent (see Code Civ. Proc., §§ 1159-1179a; Civ. Code, § 1951 et seq.) do not preclude a defense based on municipal rent control legislation enacted pursuant to the police power imposing rent ceilings and limiting the grounds for eviction for the purpose of enforcing those rent ceilings." (Id., at pp. 148-149, emphasis added, citing Inganamort v. Borough of Fort Lee (1973) 62 N.J. 521, 537 [303 A.2d 298] and Warren v. City of Philadelphia (Pa. 1955) 382 Pa. 380, 385 [115 A.2d 218]; see also Fisher v. City of Berkeley (1984) 37 Cal.3d 644, 704-710 [209 Cal. Rptr. 682, 693 P.2d 261].)
(3) The purpose of section 1161a of the Code of Civil Procedure was to make clear that one acquiring ownership through foreclosure could evict by a summary procedure. "Historically a cause of action for unlawful detainer was available only to a landlord against his tenant. (Hewitt v. Justice's Court [1933] 131 Cal. App. 439 [21 P.2d 641].) The remedy has been expanded by statute to additional categories of plaintiffs (Code Civ. Proc., § 1161) and defendants (Code Civ. Proc., § 1161a).... The policy behind the statute is clear ...: to provide a summary method of ouster where an occupant holds over possession after sale of the property." (Evans v. Superior Court (1977) 67 Cal. App.3d 162, 167-168 § 136 Cal. Rptr. 596].) (2b) Since section 1161 does not preempt a defense to an unlawful detainer action based upon rent control legislation, it follows that section 1161a also does not preempt a defense.
Real party calls this court's attention to the case of People v. Little (1983) 143 Cal. App.3d Supp. 14 [192 Cal. Rptr. 619], decided by the appellate department of the Los Angeles Superior Court. In Little a purchaser at a foreclosure sale sought to raise the rent of the tenant who occupied the premises prior to foreclosure from $65 per month to $165 per month. The tenant refused to pay the increased rent and the new owner obtained possession pursuant to section 1161a. Immediately after obtaining the judgment, the owner entered into a new lease with the same tenant for $175 per month. The owner was convicted of five misdemeanor counts for violation of the Los Angeles Rent Stabilization Ordinance. The appellate department affirmed the convictions but did not suggest that the eviction pursuant to section 1161a was improper. To the extent that the case is relevant, it supports petitioners' position. The fact that the appellate department did not *272 suggest that the eviction was improper is not significant since the issue was not raised.
We hold that section 1161a of the Code of Civil Procedure does not preempt section 37.9(a) of the San Francisco rent stabilization ordinance. Section 1161a is procedural and provides a method for recovery of possession of real property. On the other hand, section 37.9(a) is substantive in that it limits the grounds for eviction. Passage of such legislation by local government is an exercise of police power which substantively places a limitation on the owner's property rights.

II
(4a) Both real party and amicus have questioned whether the City and County of San Francisco has the power to enact ordinances which are contrary to established contract and real property principles. They maintain that foreclosure of a mortgage or lien under a deed of trust extinguishes a leasehold interest and no landlord-tenant relationship exists between the purchaser at a foreclosure sale and the tenant of the mortgagor or trustor. Real party and amicus cite McDermott v. Burke (1860) 16 Cal. 580, 589, in which the court stated "that the legal rights of the lessee were extinguished by the proceedings in the foreclosure suit and sale following the decree thereon.... There is no privity of contract or of estate between the purchaser upon the decree of sale and the tenant. The purchaser may, therefore, treat the tenant as an occupant without right, and maintain ejectment for the premises.... The relation between the purchaser and tenant is that of owner and trespasser, until some agreement, express or implied, is made between them with reference to the occupation."
However, the Supreme Court in Birkenfeld v. City of Berkeley, supra, 17 Cal.3d 129, made it clear that such contract and real property principles do not bar legislative action. For example, in Birkenfeld the court held that a local rent control ordinance could prevent eviction of a tenant after his term had expired. Under general principles of law, any contract or real property interest would have expired at the end of the term. Just as in the situation after foreclosure, no landlord-tenant relationship would exist. The rent control ordinance by its operation created a tenancy despite the existence of contract and real property principles which would have otherwise precluded the tenancy. (5a) However, as Birkenfeld holds, it is "settled California law that legislation ... restricting contractual or property rights is within the police power if its operative provisions are reasonably related to the accomplishment of a legitimate governmental purpose." (Id., at p. 158.) (4b) Here San Francisco passed a rent stabilization ordinance with the *273 legitimate and compelling governmental purpose of halting excessive rental increases due to a housing shortage.
The Supreme Court in Birkenfeld explained that a city derives its power to pass rent control legislation which abrogates general contract and real property principles from the California Constitution. (5b) "The Constitution itself confers upon all cities and counties the power to `make and enforce within [their] limits all local, police, sanitary, and other ordinances and regulations not in conflict with general laws.' (Cal. Const., art. XI, § 7.) A city's police power under this provision can be exercised only within its own territory and is subject to displacement by general state law but otherwise is as broad as the police power exercisable by the Legislature itself. [Citations.]" (17 Cal.3d 129, 140.)
The fact that the deed of trust predated the rent control ordinance does not preclude application of the ordinance to real party. We liken the legislative power in this regard to the power to enact zoning legislation, a power also derived from the general police power. (6) The legislative body may enact zoning laws despite the fact that contracts made and property rights created prior to the enactment of the law are adversely affected. (See, e.g., William C. Haas v. City & Cty. of San Francisco (9th Cir.1979) 605 F.2d 1117, 1120.) No impairment of contract is involved. Parties may, of course, provide in their contracts that property may not be rented but they may not provide that the property will not be subject to future zoning or rent control legislation. The lenders' complaint is that their investment, rather than their contract, is impaired. Here, as with zoning ordinances, however, the right of the legislative body to enact legislation "`is not limited by the fact that the value of investments made.... prior to any legislative action will be greatly diminished ...'" (People v. Johnson (1954) 129 Cal. App.2d 1, 10 [277 P.2d 45].) The zoning ordinance is to be tested "`solely by the answer to the question is there any reasonable basis in fact to support the legislative determination of the regulation's wisdom and necessity?'" (G & D Holland Construction Co. v. City of Marysville (1970) 12 Cal. App.3d 989, 994 [91 Cal. Rptr. 227].) Birkenfeld makes clear that this general test applies to rent control legislation as well. (Birkenfeld v. City of Berkeley, supra, 17 Cal.3d 129, 165.)
(4c) We fail to find that the general principles of law cited by real party and amicus act as a bar or impediment to the enactment by a city of a rent stabilization law limiting the grounds for eviction. Quite to the contrary, Birkenfeld approves such a legislative act so long as there has been no preemption by the state Legislature.


*274 III
(7) Next, real party argues that, even if there has been no preemption of the subject of grounds for eviction, and, even if general principles of law do not bar local ordinances addressing this subject, the San Francisco ordinance on its face is not applicable to a purchaser at a foreclosure proceeding. Such a purchaser, real party contends, is not a landlord and a landlord-tenant relationship was never established between itself and petitioners.
"Landlord" is defined in section 37.2(h) of the San Francisco rent control ordinance as follows: "An owner, lessor, sublessor, who receives or is entitled to receive rent for the use and occupancy of any residential rental unit or portion thereof in the City and County of San Francisco, and the agent, representative or successor of any of the foregoing." A purchaser of property, as successor to the "landlord," is subject to the ordinance and thus the municipal court recognizes that the "voluntary purchaser ... would step into the shoes of the seller and would have to comply with the Rent Ordinance." The ordinance does not require that the landlord-tenant relationship be initiated by the parties for such a relationship to exist.
Real party maintains that a purchaser at foreclosure is not within the scope of landlord as set out in the San Francisco ordinance. Real party argues that it is not a "successor" to the landlord but a "predecessor," apparently on the theory that its interest as beneficiary under the deed of trust "preceded" in time and priority the tenancy of petitioners. Real party appears to be mixing concepts. It is not real party's "priority" to the tenant which is relevant. The relevant positioning of parties for purposes of the ordinance is that of real party and the defaulting landlord. Real party's position as "owner" "succeeded" rather than "preceded" that of the defaulting landlord. The defaulting landlord of the premises was entitled to receive rent. Real party succeeded him as owner and was likewise entitled to receive rent if it chose to do so. It became a "landlord" by operation of law. The fact that it was not a "voluntary purchaser" in the sense that purchase was necessary to protect a security interest is not an exception recognized on the face of the ordinance.
In Lovett v. Bell (1947) 30 Cal.2d 8 [180 P.2d 335], the Supreme Court considered the landlord-tenant relationship under the Rent Regulation for Housing in effect in 1942. The Rent Regulation defined landlord and tenant in similar language to the definitions of the ordinance under consideration. The court commented: "The chief consideration under these definitions seems to be the character of the initial occupancy of the property as housing accommodation. If the occupant originally took lawful possession of the *275 premises as a tenant, he remains such for the purposes of the Rent Regulation no matter what change in ownership occurs and regardless of whether under local law he is technically a `tenant.' [Citation.] For example, a purchaser of rental property at a lien foreclosure sale may not oust a tenant in possession except in pursuance of the Rent Regulation specifying the grounds for eviction. [Citations.]" (Id., at p. 13.)
Real party contends that any interpretation of the Rent Regulation for Housing which was part of the Emergency Price Control Act of 1942 cannot have precedential value in interpreting the present ordinance because circumstances leading to that wartime legislation differ so markedly from the circumstances leading to the present rent control legislation. We find to the contrary. The general legislative intent of the San Francisco Board of Supervisors to enhance the availability of affordable housing is explained in its findings in section 37.1(b) of the rent control ordinance and from its declaration of emergency in section 37.13. The board found that a housing shortage existed which led to a problem of rent increases which had reached "crisis level" at the date of enactment of the legislation. (§ 37.1(b)(3).) The legislation is addressed to this problem of rent increases "along with the concomitant hardships and displacements." (§ 37.1(b)(5).) The problems addressed by rent control legislation are the same whether those problems are the result of a wartime or peacetime housing shortage. The power of local Legislatures to pass rent control legislation is not an exercise of a "wartime" power but an exercise of the police power conferred on all cities and counties by the California Constitution to "make and enforce within [its] limits all local, police, sanitary, and other ordinances and regulations not in conflict with general laws." (Cal. Const., art. XI, § 7; see Birkenfeld v. City of Berkeley, supra, 17 Cal.3d 129, 140.)
The prevention of eviction without cause obviously works to fulfill the intent of the rent control ordinance. Once the landlord-tenant relationship ceases to exist, the landlord is not constrained in the base rent charged for the unit since the definition of tenant, unlike the definition of landlord, does not include the "successor" of the tenant. (§ 37.2(r).) Whenever a unit is vacated, therefore, the purpose of the legislation to further the supply of affordable housing is to some extent thwarted. The limitation of evictions not only keeps rents under control but limits the numbers of persons uprooted from "controlled" units and forced to relocate in units which have been temporarily "decontrolled." The eviction provisions in the rent control ordinance are integral to the purpose of the legislation. Nothing in the language of the eviction provisions or in the ordinance as a whole suggests that the board intended to exempt from its provisions units which have changed ownership through foreclosure proceedings.


*276 IV
(8) Finally, although no California court has ruled on whether a purchaser at a foreclosure sale or a trustee's sale may evict a tenant from a rent controlled unit without cause, the question has been addressed in the courts in New York. In United Institutional Servicing Corp. v. Santiago (1970) 62 Misc.2d 935 [310 N.Y.S.2d 733], a purchaser at a foreclosure sale sought possession of a rent-controlled apartment occupied by tenants. Under New York state law no landlord-tenant relationship existed and the purchaser was entitled to bring an action for possession but the court held that the purchaser could only do so by complying with the provisions of the Rent, Eviction and Rehabilitation Regulations of the City of New York. The court quoted with approval the following language from Da Costa v. Hamilton Republican Club (1946) 187 Misc. 865 [65 N.Y.S.2d 500], reconciling the judgment of foreclosure with the regulations: "`The primary purpose of the judgment of foreclosure is to divest the mortgagor of ownership and to make the property, or its proceeds, available to the mortgagee in satisfaction of his claim. This transfer of title is neither affected by the emergency statutes, nor does it affect the right of occupants under those statutes, except as specifically provided. Section 8(d) describes the circumstances in which a new owner may remove an occupant. The purchaser at a foreclosure sale should be in no stronger position than the ordinary vendee. The plaintiff may evict the defendant if the requirements of Section 8(d) are met. He should not, however, be allowed to substitute the present motion for a dispossess proceeding brought in accordance with the emergency rent laws, nor should he be permitted to deny to this occupant the protection afforded other lawful occupants merely because of the presence of the language traditionally employed in judgments of foreclosure.'" (Id., at pp. 736-737.)
We hold that real party in interest failed to demonstrate that it had grounds under the San Francisco Residential Rent Stabilization and Arbitration Ordinance to evict petitioners. This failure is a proper defense by petitioners to an unlawful detainer action under section 1161a.
Let a peremptory writ of mandate issue directing the San Francisco Municipal Court to vacate its judgment entered in the case of Victoria Mews Consortium v. Herb Gross, James Miller, No. 853903, on July 6, 1983, and to enter judgment in favor of petitioners.
Kline, P.J., and James, J.,[*] concurred.
A petition for a rehearing was denied September 19, 1985, and the petition of real party in interest for review by the Supreme Court was denied October 17, 1985. Mosk, J., and Lucas, J., were of the opinion that the petition should be granted.
NOTES
[1]  The motion to dismiss was based on the fact that petitioners have returned possession of the premises to real party. We denied the motion to dismiss, however, applying the principle that: "If an action involves a matter of continuing public interest and the issue is likely to recur, a court may exercise an inherent discretion to resolve that issue, even though an event occurring during its pendency would normally render the matter moot. [Citations.]" (Liberty Mut. Ins. Co. v. Fales (1973) 8 Cal.3d 712, 715-716 [106 Cal. Rptr. 21, 505 P.2d 213].)
[2]  At the time of the eviction proceeding section 1161a of the Code of Civil Procedure provided: "In any of the following cases, a person who holds over and continues in possession of real property after a three-day written notice to quit the property has been served upon the person, or if there is a subtenant in actual occupation of the premises, also upon such subtenant, as prescribed in Section 1162, may be removed therefrom as prescribed in this chapter:

"(1) Where the property has been sold pursuant to a writ of execution against such person, or a person under whom such person claims, and the title under the sale has been duly perfected.
"(2) Where the property has been sold pursuant to a writ of sale, upon the foreclosure by proceedings taken as prescribed in this code of a mortgage, or under an express power of sale contained therein, executed by such person, or a person under whom such person claims, and the title under the foreclosure has been duly perfected.
"(3) Where the property has been sold in accordance with Section 2924 of the Civil Code, under a power of sale contained in a deed of trust executed by such person, or a person under whom such person claims, and the title under the sale has been duly perfected.
"(4) Where the property has been sold by such person, or a person under whom such person claims, and the title under the sale has been duly perfected." (Stats. 1982, ch. 497, § 74, p. 2167.)
[*]   Assigned by the Chairperson of the Judicial Council.
