Ahmed Kadesh, 5, from Damascus, sleeps on the ground Sept. 15, 2015, near a wall along the Hungary border. (NurPhoto)

Like it or not, Donald Trump isn’t the only one in the world looking to build a wall to keep out immigrants. Since the migrant crisis in Europe, Hungary and several other European states have begun planning or erecting border fences of their own, which have been referred to as “new iron curtains.” Going back further, 34 interstate fortified boundaries have been built since 1990, not including the recently constructed European ones.

What explains this trend? Why do leaders and countries build border walls or fences?

In a recent article in International Security, “Barriers to Entry: Who Builds Fortified Boundaries and Why?” we tried to understand why states fortify their borders with a wall, fence, or other structure. To do so, we created a new dataset encompassing all 319 pairs of contiguous states worldwide. Forty-five of these borders have featured fortified boundaries since 1945, but we focus on the 34 that have been built since 1990.

By comparing country pairs that have fortified boundaries to country pairs that do not, we were able to identify what kinds of states construct such boundaries and what kinds of countries are being fenced out.

Why build a wall? To keep out poverty and Muslims.

Dramatic differences in economic opportunity between neighboring countries are often what propel states to construct barriers. Our data show that when there’s a significant wealth gap between two countries, the wealthier state becomes more likely to fortify its border. Among those country pairs that feature barriers, the states building the wall are on average nearly four times as wealthy (per capita) as the states whose citizens are being kept out. Think of the attempts at fortifying the U.S.-Mexico border as but one example.

But keeping out poverty isn’t the only reason states fortify borders. Of 34 barriers built worldwide since 1990, 29 were constructed to keep out citizens from Muslim-majority nations. This isn’t just rank Islamophobia, however. Muslim-majority states built 17, or 59 percent, of those 29 barriers against Muslim-majority targets. Put differently, half of all fortified boundaries worldwide since 1990 separate Muslim states from other Muslim states.

Samuel Huntington famously stated that “Islam has bloody borders,” a reference to borders between the Muslim world and the non-Muslim world. Our data suggest that the Muslim world is uniquely likely to build walls. Of 72 bilateral intra-Muslim contiguous boundaries, 17 — or nearly 24 percent — have barriers. By contrast, out of 191 bilateral non-Muslim contiguous boundaries, only four, or 2 percent, feature barriers.

Although keeping out poverty and Muslims may be the main prompts to building barriers, that’s not what nations actually say. We find that states frequently cite fears of terrorism to justify building walls. We find no evidence, however, that the states that build border walls have experienced a disproportionately large number of terror attacks. Wealth gaps and religion explain more of the story.

But aren’t fences hard to build and expensive?

We might think fortifying a border is too difficult or expensive for most states (plans to get Mexico to pay for a fence aside). States don’t seem to think so.

In other words, governments are not deterred by construction challenges or high costs. Several of the world’s barriers cover tremendous distances, traverse incredibly demanding terrain and cost states huge sums of money. For example, Morocco has built the Berm, an approximately 1,700-mile-long system of sand and stone wall barriers, in one of the most desolate places on earth: the Western Sahara. That’s equivalent to the distance from Washington, D.C., to Denver, Colorado.

Nor was cost a deterrent for Morocco. Designed to thwart incursions by the Polisario Front, an insurgent movement representing the indigenous Sahrawi population of Western Sahara, the Berm cost an estimated 40 percent of Morocco’s GDP to build and defend.

For all that money, do fortified borders work?

It’s complicated.

First, data on fortified boundaries and illegal border crossings are hard to come by. Governments have little incentive to publicize these figures.

Second, we can’t run a clean experiment to see what a situation would be if a country had left the border unfortified or if a state had used an alternative to a fortified border. Only focusing on fortified borders ignores situations where unfortified borders may be just as, or even more, effective for other reasons.

Third, any assessment of barrier effectiveness must ultimately account not just for its “stopping power,” but also for its long-term strategic consequences, an even tougher dynamic to measure.

Nonetheless, two factors seem to make borders more or less effective.

Walls work if they’re part of a larger border strategy

Walls don’t work by themselves. They must be backed by a broader repertoire of border control measures, especially including efforts to guard the wall. Without that, migrants can circumvent the fortified boundary or even target the fortifications to weaken or destroy them.

The most effective way a state can protect a fortified boundary is to control territory on both sides of the boundary. This can occur in two ways. One is for a state to build the barrier slightly inside its own territory so it can patrol both sides without going into its neighbor’s territory. The other is to build the barrier right on the border, but surveil the other side without putting boots on the ground. Either way, the fortified boundary can be effectively protected.

Rule out alternate routes into the country

Second, we hypothesize that walls are less effective if would-be migrants can find other ways to get into the country. Because they will, indeed, look for ways around the wall. And if they succeed, fortification becomes irrelevant. In short, if there is a hole in the fence, chances are that migrants will find it.

The recent epidemic of European fences can be seen as an effort to close the gaps in the fence between Europe and the Middle East. After Hungary finished its fence along the Serbian border, asylum seekers went to Croatia, which prompted both Hungary and Slovenia to construct new fences along their Croatian borders.

In the U.S. case, the holes are as much metaphorical as literal, although those exist too. No one particular boundary controls entry and exit. If undocumented migrants from Mexico can’t get across the border on foot, they can come in at any U.S. port and airport, or even the U.S.-Canada border. Given the myriad airports and ports across the U.S., it’s hard to see how a U.S.-Mexico border fence actually keeps out motivated immigrants.

Building a barrier might create its own set of new problems. Impeding human and material traffic increases the financial rewards for smuggling. A wall might thus encourage rather than discourage illicit cross-border activities. Or a wall on one part of a border might simply shift traffic to other regions which may have been previously free of trafficking.

And finally, it won’t put an end to terrorism. Border barriers might drastically reduce the influx of terrorists, as it has in the case of Israel’s fortified barriers with the West Bank and Gaza, but they won’t persuade determined opponents to give up. It’s more likely that opponents will find another means of attack. In Gaza, for example, Palestinian terrorists, stymied by a fortified barrier, switched from suicide attacks to short- and medium-range rockets and mortar attacks.

States may be able to address these perverse effects. But it’s clear that a barrier alone is not a silver bullet, whichever side you’re on.

Ron E. Hassner and Jason Wittenberg are associate professors of political science at the University of California, Berkeley. Hassner is the author, most recently, of “Religion on the Battlefield.” Wittenberg is the author of “Crucibles of Political Loyalty: Church Institutions and Electoral Continuity in Hungary.”