A federal judge struck down a city law on Tuesday that would have banned employers in Philadelphia from asking potential hires about their past earnings, an attempt to close the gap between what men and women earn in the city.

The ruling by the judge, Mitchell Goldberg of United States District Court in Philadelphia, was a victory for the Chamber of Commerce of Greater Philadelphia, which had sued the city to challenge the law set to take effect later this month.

In his ruling, Goldberg wrote that while the law was “a significant positive attempt to address the wage gap,” the way it was written violates the First Amendment free speech rights of city employers.

It was unclear whether the city would appeal the decision or try to devise a different version of the law.

Comcast, the Children’s Hospital of Pennsylvania, and other major employers in the city joined the Chamber of Commerce in opposing the ordinance, which the interest group called “anti-business” and claimed would “impair the creation of new jobs in the city.”

On average, women in Pennsylvania earn 79 cents for every dollar paid to a man for comparable work; for African-American and Latina women, the disparity is even greater.

Supporters of the law maintained that the wage gap takes hold early on in someone’s career. By taking a worker’s past earnings out of the equation, they say, women and men may start receiving more equitable salaries.

But business groups fought back, saying the law would have unintended consequences that would make the city less business friendly.

In a statement, Chamber spokeswoman Danielle Hagerty said the business group agrees that gender wage inequity needs to be addressed, yet “the method chosen by the city” was not the right one, Hagerty said.

Under the law, employers caught asking about a prospective employee’s last earnings could be fined $2,000 per violation by the city, a set of sanctions, the Chamber argued, that could cause businesses to move outside of city limits to avoid the hassle.

Mike Dunn, a spokesman for Philadelphia Mayor Jim Kenney, said the city is “evaluating its options” after the federal judge’s ruling.

Dunn pointed to another part of the decision upholding the city’s authority to enact such a law. The city is “encouraged” by that determination. “In doing so,” Dunn wrote, “it upheld a key aspect of the legislation.”

Yet the more impactful and immediate effect of the judge’s ruling blocks the law from taking effect in three weeks, as its supporters had hoped would happen.

Goldberg, in his ruling, questioned whether the law would indeed narrow the gender pay gap. He said those who testified about the law’s intended effect to City Council did not present scientific evidence.

“The critical problem for the city is, however, that these avowals are unsubstantiated conclusions,” Goldberg wrote. “While the witnesses who presented to City Council are experienced in their respective fields, their observations are mostly conjectural in nature.”